-
Notifications
You must be signed in to change notification settings - Fork 757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Byte Type Aliases with Byte Length Indicators #3335
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. |
This is lovely. We should definitely do this across the monorepo. |
I like this! One thing that came up while searching the monorepo, is that we have some exported Bytes32 and other similar types in the client, but in that case they served as aliases for |
export type PrefixedHex8 = string | ||
export type PrefixedHex20 = string | ||
export type PrefixedHex32 = string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be updated to PrefixedHexString rather than string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not see the advantage of such alias chaining TBH.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah you're right, but I was thinking in the context of that other PR (where PR was updated to 0x${string}
).
Yes, that makes definitely sense to align in client, would also agree with the Bytes == Uint8Array stuff. The whole PR is currently (and maybe permanently block). Context is that the type aliases do not propagate through in the editor (Visual Studio Code), so hovering over the code then shows Jochem actually tried the same thing as here already some time ago (didn't know that before) and stumbled upon the very same thing (and therefore drew the same conclusion here). We'll see. Would be really really nice to have something like this. Maybe also worth to have a look at other low-level libraries for some inspiration. |
This is on my plate for a very long time, PR adds simple byte aliases for both
Uint8Array
andPrefixedHexString
with byte length indication.As discussed already quite some time back ago, this implementation has none of the eventual backlashes as stricter solutions (like performance drawbacks on actual length checks everywhere in the code base) and should at the same time already bring a lot of the benefits, mostly being a lot better documented function signatures and length hints. VSC mouseover of the one exemplaric type in Block e.g. now look like this:
For the
PrefixedHex*
thing I tested (and "stared" for quite some time 😂) at the different flavors of a possible naming scheme:PrefixedHexString20
PrefixedHexStr20
PrefixedHex20
I came to the conclusion that the last version should be sufficiently expressive and is at the same time the easiest to grasp, with the need to only digest 3 word parts instead of 4 (which is a lot), and after 3-4 rounds of usage latest it should be very intrinsic that this is about a string (if not clear from the beginning). So this version would be my personal favorite.
I would give this open for a first look and feedback and then continue a bit with it.
We do not need to get to completion here and merge this in a selectively applied state. Then we can just replace types over time, this is otherwise too tedious to accomplish in one go.