4 ms·
While theoretically I accepted with all the points, in practice it is sometimes too bloated to add so many types that are barely distinct. It is sometimes bette
by conaclos 4y ago
While theoretically I accepted with all the points, in practice it is sometimes too bloated to add so many types that are barely distinct. It is sometimes better to trade safety for simplicity.
The trade-off is always hard to make.
For instance: should I introduce a branded type for unsigned 32bit integer in TypeScript?
type u32 = number & { [U32_BRAND]: never }
const u32 = (n: number): u32 => (n >>> 0) as u32
And then to make it hard any use of this type:
declare let x, y: u32
y = u32(x + 1)
- Hackbraten 4y agoI just learned that there’s an open issue [0], apparently for introducing a similar feature. [0]: https://github.com/microsoft/TypeScript/issues/43505 https://github.com/microsoft/TypeScript/issues/43505