tgerboui / nona-lib

TypeScript library to simplify interactions with the Nano currency node.
MIT License
6 stars 1 forks source link

Improve type safety with branded types #7

Open luxbe opened 2 months ago

luxbe commented 2 months ago

Throughout the project, there are lots of references to "string". This is great for a quick start, but leads to possible mistakes. For example a Hash has the same type as a PrivateKey, even if they represent different concepts!

As a dev I want to use typescript types to get at least some level of safety, by introducing type aliases that cannot be converted into each other by mistake. This concept is called branded types: https://egghead.io/blog/using-branded-types-in-typescript

With this, types can also be verified more easily, e.g. PrivateKeys should always be of length X. @tgerboui what do you think of this concept? I would love to implement it!

tgerboui commented 2 months ago

Great Idea !

If you're motivated, go for it !