4 ms·
Typescript's single biggest win for me is the ability to provide type definitions for my models. This is where the vast majority of my JS bugs come from -- some
by ng12 10y ago
Typescript's single biggest win for me is the ability to provide type definitions for my models. This is where the vast majority of my JS bugs come from -- somebody trying to access a nonexistent property of some object (or, if it does exist, incorrectly assuming the type) which was serialized from JSON. Better yet, if you write your back-end in Node you can use the same models in your rest endpoint. It's a huge boost to both maintainability and developer productivity.
However, my biggest frustration with Typescript is the general unreliability of @types. The odds that a given set of typings are complete, correct, and up-to-date are basically nil -- even for some relatively popular projects. Sad to say I've become an expert in Typescript's crazy module augmentation nonsense. Hopefully more big players like Slack contributing to DT will help.
- whatever_dude 10y agoIn my ideal world, every library would be written in TypeScript and therefore benefit from their automatic type definition output, shipped as an invisible part of their npm package.
- rattray 10y agoFor anyone unfamiliar: DT is "DefinitelyTyped", a github repo that consolidates type declaration files for open-source packages on npm. Ironically, given the above comment, its tagline is: > The repository for high quality TypeScript type definitions. (emphasis theirs) https://github.com/DefinitelyTyped/DefinitelyTyped https://github.com/DefinitelyTyped/DefinitelyTyped
- sadlion 10y agoHow does one validate typescript models at runtime? I have seen combinations of JSON schema and validator libraries but I'd love to do it using typescript's type system. From my understanding, it doesn't work because of type erasure.
- ng12 10y agoAFAIK there's no good solution. That's why it works best when your back end is using Typescript as well -- your route returns the same interface the client is expecting.
- STRiDEX 10y agoYou don't. You'd have to use something like https://github.com/hapijs/joi https://github.com/hapijs/joi
- gcanti 10y agoThis is a TypeScript compatible runtime type system for IO validation https://github.com/gcanti/io-ts https://github.com/gcanti/io-ts