Re:Hegel – An advanced static type checker for JavaScript
by mcluck on Thursday October 13, 2022 @05:58AM
(#33189139)
I agree and I'd like to add that if someone wants to throw an error for invalid type casts, they can use assertion functions.
https://www.typescriptlang.org/docs/handbook/release-notes/t...
Re:Hegel – An advanced static type checker for JavaScript
by eyelidlessness on Thursday October 13, 2022 @12:28PM
(#33193227)
That’s an option I considered mentioning, but it has some weird ergonomics that many people won’t like.
That’s a runtime type check! Any equivalent you might bake into TypeScript would do the exact same thing, but it would do it rigidly in ways people don’t expect (being strict about input types, ie “do what I say not what I mean) or rigidly in ways people don’t expect (“do what I mean as long as you mean exactly what we allow”). Again, fine grained type guards as implemented by zod/io-ts/etc solve this problem and either give you all you need already or demonstrate exactly how you can use existing language features to achieve exactly what OP and anyone else asking for runtime types wants.