4 ms·
a common misconception is that TypeScript[TS] will provide runtime safety; it won't unless you specifically add functions for it, like the type casts presented
by HugoDaniel 6y ago
a common misconception is that TypeScript[TS] will provide runtime safety; it won't unless you specifically add functions for it, like the type casts presented in the article.
The typecast approach presented in the article can be combined with TS to provide runtime type safety; They are not entirely opposite/alternative approaches but complementary.
- depmann 6y agoYes, TS and typecasting can live well together. However, once you combine sensible naming by type and typecasting together, the benefits of TS fade. Then one has to ask: are the remaining benefits worth the expense of running a full TS transpiling infrastructure? In my case, the answer is a definitive 'no'. Typecasting along with Webstorm introspection virtually eliminate may of the issues that TS was designed to solve.
- wereHamster 6y agoFor most of my day-to-day projects, there is no TS transpiling happening at all, .ts/.tsx files are supported by many toolchains in the very same way .jsx files are supported (without any additional overhead over the regular transpiling that is required for any modern JS project). TypeScript is really only active within my editor, not during bundling. This gives me reliable intellisense, code completion, jump-to-definition, rename-symbol, and other IDE features across the whole project. > Typecasting along with Webstorm introspection virtually eliminate may of the issues that TS was designed to solve. I personally don't want to stop at /virtually/ eliminating issues that arise due to type errors. I want to /reliably/ eliminate them. And the only way to eliminate type errors is to run a static type checker over the project. (I know the TS type system is not 100% sound, but most definitely better than manual typecasting at runtime).
- williamdclt 6y agoThere's a library called runtypes (https://github.com/pelotom/runtypes https://github.com/pelotom/runtypes) that integrates TS and Typecasting quite nicely
- wereHamster 6y agoAlso https://github.com/gcanti/io-ts https://github.com/gcanti/io-ts