3 ms·
That is outside of the scope of TypeScript, which is to be a statically typed superset of JavaScript with no runtime cost. It's easy enough to write a runtime
by jakelazaroff 6y ago
That is outside of the scope of TypeScript, which is to be a statically typed superset of JavaScript with no runtime cost.
It's easy enough to write a runtime type checking library; I wrote a tiny one that I use in basically all my projects: https://npmjs.com/package/narrows https://npmjs.com/package/narrows
- wonderlg 6y agoWith your library one has to write types twice. I understand that it’s not TypeScript’s job at the moment, but it’d be great to enable runtime checks with the flick of a switch without typing extra code. function upper(s: string) { return s.toUpperCase(); } This function could have a nice implicit TypeError instead of “undefined is not a function”
- jakelazaroff 6y agoI’m not sure what you mean. My library has a `TypeOf` type that lets you extract static type information from validation functions. And calling `toUpperCase` on undefined already results in a TypeError.
- joepie91_ 6y ago> That is outside of the scope of TypeScript, which is to be a statically typed superset of JavaScript with no runtime cost. Yes, that is the thing being criticized here.