-
-
Notifications
You must be signed in to change notification settings - Fork 291
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
Better .valueOf() #2419
Comments
👍 A typesafe wrapper would be really nice. I suggest something like this exported from function toStruct<T extends CompositeValue>(value: T): T extends ByteVector ? Uint8Array : T {
if (isTreeBacked(value)) {
return value.toStruct();
}
return value;
} A note about the name, its not that we're dropping the tree but rather that we're converting the tree to a "struct", ie a primitive javascript datatype. (our |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 15 days if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 15 days if no further activity occurs. Thank you for your contributions. |
Describe the issue
Using
.valueOf() as SomeType
is not type-safe at all and can become dangerous an unmaintainable.We are using it for a very specific purpose which is to drop the tree and get the actual internal value without wrappers. This meaning is not easy to get at first glance.
Proposed solution
Create a helper function that clearly shows what it does that AND is type safe.
With this code would read like
instead of
Related to #2408
The text was updated successfully, but these errors were encountered: