4 ms·
I see readability as a key advantage of TS. Once you are able to comfortably read type signatures, it is trivial to see what a function is supposed to do, or wh
by erikw 6y ago
I see readability as a key advantage of TS. Once you are able to comfortably read type signatures, it is trivial to see what a function is supposed to do, or what a library is supposed to provide. When things don't work as expected, then it's just a matter of hopping into the debugger to inspect data inflight to find where the typings aren't matching up with reality.
- dgoldstein0 6y agoyup, types are a huge advantage, especially in large codebases where you probably don't know all the people who may write code to interact with your code. Readability of types can become an issue over time, but with the right naming of interfaces and useful type aliases, that can be mitigated to some extent. And as the typescript language and community evolve together, there are new ways to make some types even more readable - I've seen generics for getting the return type of a function, which seems potentially really useful (and some people swear by; I haven't used them extensively, but it looks like a promising idea).
- momokoko 6y agoAfter ten years of JavaScript and after working on TypeScript apps that have now been around for 5+ years, I can assure you TypeScript is less maintainable long term than most languages. Did you know that TypeScript’s type system is turing complete? Good luck figuring out literal bespoke type frameworks in TypeScript. Did you know you can have a TypeScript application that takes more than 8GB of memory to compile? TypeScript is literally a Microsoft play to regain Visual Studio market share they lost by creating a language that much like C# and Java, practically speaking, requires a massive feature rich IDE for most developers to write software efficiently with. You all fell for it, and at this point it’s too late. Millions of extra development hours will wasted maintaining legacy TypeScript apps for years due to a Microsoft marketing stroke of genius.
- d3nj4l 6y agoIf genuine developer satisfaction from everyone I know IRL who's used typescript is due to Microsoft's marketing, I say they deserve to win this one.
- Shacklz 6y ago> where the typings aren't matching up with reality. There are also libraries which provide runtime type validation, such as zod or io-ts. Can only recommend; they allow that in combination with typescript's strict mode your types become completely reliable.
- 2019-nCoV 6y agoIt is not at all trivial to see what a function is supposed to do from its type sig. There are an infinite number of valid type safe implementations for: transform(a: number): number
- keymone 6y agoIt makes a number out of a number. Type signature isn’t supposed to explain the implementation, just the interface.
- hombre_fatal 6y agoSomething you run into when adding Typescript annotations to existing JS / libraries in the wild is when the signature turns out to be: function transform(a: number | string): number | "" | false And it's usually all by accident. And it works because in practice it's used with a `if (!transform(x))` check. Static typing doesn't just tell you what's going on, but it also helps you keep your implementation honest with your intent. It's also why it's a good habit to annotate top-level functions instead of relying on their inference.
- realharo 6y agoThis is especially true with `| undefined` helping address the billion dollar mistake.
- ygra 6y agoYou can sometimes use overloads to make it better: function transform(a: number): number function transform(a: string): false function transform(""): "" Depending on how predictable the output is from the types, of course. But for many things it works better than just using union types everywhere.
- 2019-nCoV 6y agoExactly. The parent post claimed: > Once you are able to comfortably read type signatures, it is trivial to see what a function is supposed to do Typing gives minimal insight into what a function actually "does". The solution is intention revealing naming, available in all languages.
- brazzy 6y agoUh... welcome to static typing. Yes, it's nice.