3 ms·
Private fields, unique symbols, there's many ways to do nominal typing in TypeScript, depending on what you want.
by rictic 1y ago
Private fields, unique symbols, there's many ways to do nominal typing in TypeScript, depending on what you want.
- eyelidlessness 1y agoI think that’s part of the problem: there’s no canonical idiom. The other part of the problem (IME) is that the biggest gap in nominal typing support is exactly what enum solves: nominal primitives. Yes, you can kinda get there with branding, but that’s a hack with a ton of footguns built in. And in many cases, you can box those values. But that can be an awful perf trade off in a hot loop, which is (again IME) often exactly where nominal primitive types would be incredibly helpful.