Hacker News new | ask | show | jobs
Show HN: Extra Types for TypeScript (github.com)
1 points by xcatliu 2072 days ago
1 comments

Unfortunately since TypeScript’s type system is structural, these type aliases will only serve as documentation, but won’t prevent assignment of incompatible types with the same underlying structure (or primitive). If you want to achieve greater nominal type safety (with the caveat that it’s only as safe as your runtime validation), I would recommend looking into the concept of “branded” types. Essentially they’re an intersection of the underlying type and some unique metadata that makes the type checker prevent invalid assignments.