Re:TypeScript: Control flow analysis for destructured discri...
by wk_end on Wednesday November 03, 2021 @08:36PM
(#29102390)
Structural typing is a sane default in JS land, but there are times that you really really want nominal typing and its complete absence from TS kind of hurts.
[ Parent
| on HN ]
Re:TypeScript: Control flow analysis for destructured discri...
by jareware on Wednesday November 03, 2021 @10:34PM
(#29103089)
FWIW, io-ts offers this via its “userland” implementation of branded types.
Re:TypeScript: Control flow analysis for destructured discri...
by rtpg on Thursday November 04, 2021 @05:28AM
(#29105002)
for what it's worth you can totally fake nominal typing in a hacky way through a sort of shiboleth key. You say "this type has `____type: 'foo'`, and on constructions of the object you just cast (or hell, just put the key in!), and you're off to the races.
This is far from perfect, but when you're working with very tricky code and want to be sure, you at least have the option
Re:TypeScript: Control flow analysis for destructured discri...
by fiddlerwoaroof on Wednesday November 03, 2021 @09:37PM
(#29102750)
Yeah, for modeling with types, you frequently want nominal types (e.g. you want to make sure that a certain types always means “the data has passed through such and such a function). Flow’s combination of structural and nominal types seems better to me than TS’s pure structural system.