News for hackers. Stuff that matters.
Re:Hegel – An advanced static type checker for JavaScript by kotlin2 on Thursday October 13, 2022 @07:07AM (#33189498)
There is a typescript library called runtypes which offers really great runtime type checking. It’s a vanilla TypeScript library, so it doesn’t require any modifications to your tool chain. It provides library functions for defining types that are very similar to how you’d define the types in typescript. Once you define the types via library functions, the library has offers access to the underlying TypeScript type using typeof and also provides checked JSON deserialization methods.
Re:Hegel – An advanced static type checker for JavaScript by hermanradtke on Thursday October 13, 2022 @07:23AM (#33189591)
There multiple libraries like this and gajus is well aware of them. They are libraries instead of being part of the language.
Re:Hegel – An advanced static type checker for JavaScript by kotlin2 on Thursday October 13, 2022 @08:13AM (#33189917)
Yes, runtypes is not the only option. But the point is that TypeScript’s type system is powerful enough to implement runtime type checking. I’m not sure what the benefit would be to adding the concept as a first-class citizen in the language.