3 ms·
Since 2.1 ts is becoming a de-facto default choice for any serious JS projects I'd say. In conjunction with VSCode it really shines and makes JS sometimes even
by anonyfox 10y ago
Since 2.1 ts is becoming a de-facto default choice for any serious JS projects I'd say. In conjunction with VSCode it really shines and makes JS sometimes even enjoyable...
But there is an issue that quirks our team almost daily: the bolted-on typesystem provides a false sense of safety. You can look at an API response, write an interface for the data structure, build functionality ontop of it, and when the API response structure changes in subtle ways over time, everything may break without notice. There is no way to enforce an interface through casting anywhere, not even via some code generation or sth like that.
- Rapzid 10y agoI believe there is a way to write type information out to decorators or something like that so you can get access to type information at run time.
- smrq 10y agoCodegen your TS interfaces from your server endpoints. You don't need run-time enforcement if you have a compile-time guarantee that the endpoint you're hitting will return a specific type back. TypeLite (https://www.nuget.org/packages/TypeLite https://www.nuget.org/packages/TypeLite) can get you halfway there with C#. I used that for a while before eventually wanting more and rolling my own solution, which takes a WebAPI endpoint and generates typed fetch methods. It's not anywhere close to polished or reusable, unfortunately.
- Nemo157 10y agoUse something like https://github.com/lbovet/typson https://github.com/lbovet/typson to generate a JSON schema for your interfaces, then use a JSON schema validator before casting the API response to your interface. I haven't touched TS since ~1.3, but this was all working well back then at least.
- sceutre 10y agoTypson hasn't been updated for a while, we use https://github.com/YousefED/typescript-json-schema https://github.com/YousefED/typescript-json-schema which works with recent typescript coupled with https://github.com/mafintosh/is-my-json-valid https://github.com/mafintosh/is-my-json-valid
- pininja 10y agoIf you're using F# backend, Gluon generates a typescript RPC. Its saved my team many times. http://www.tachyus.com/gluon/ http://www.tachyus.com/gluon/
- mythz 10y agoServiceStack's solution for this is to generate TypeScript DTOs from Server DTO classes for use with its generic JSON Service Client to enable its end-to-end Typed API: http://docs.servicestack.net/typescript-add-servicestack-reference http://docs.servicestack.net/typescript-add-servicestack-ref... Disclaimer I work for ServiceStack