Ask HN: Why JavaScript experts tend to not use TypeScript?
The creator of Preact/Signal
https://twitter.com/_developit/status/1570973592665620482
The creator of uhtml/usignal https://twitter.com/WebReflection/status/1272276063222222852
The creator of Svelte (not go all-in) https://twitter.com/Rich_Harris/status/1350436286948122625
And many others experienced devs I didn't collect evidence that it's hard to dig later.
Mostly they do just because folks on github demand support, to satisfy audience.
22 comments
[ 4.7 ms ] story [ 64.5 ms ] threadThere are specific reasons depending on the project context.
What I'd expect is .. oh those mostly write libs and frameworks so it's not good fit for that, but then .. well the world of software is compose of libraries.
Public discussion is good! I think that's the point of Ask HN.
I think somthing similar may happen to TS.
I know I can eject the types and go back to ES, but at this point I trust TS is going to be highly relevant for at least 5 years with a long tail.
The creator of uhtml believes there are transpilation bugs. I can't say whether this is true, but if it's an issue for them, I guess that's a valid reason.
Jason Miller's tweet also includes a common reason: he isn't good at it and doesn't understand it, or in his words "the amount of time I have to spend screwing up my already-working code to make TypeScript happy". This is a big one. TypeScript is hard, and poorly written TypeScript increases complexity. My last job was a TS codebase written by people who didn't understand it and it was a major impediment to productivity.
The Rich Harris tweet represents a common misunderstanding about TypeScript types. If your types can be represented by primitives like `string` or `number`, then his JSDoc approach is fine, but when writing TS those sorts of primitives are barely scratching the surface. For example, TS has a powerful Generics syntax that cannot be duplicated in a code comment.
TypeScript is very complex because it needs to be able to type all valid JS code, which means being able to describe things that most other languages would never even allow. JavaScript is very flexible and permissive, and all of us are used to working with them in a way that's hard to type. One of the first steps in learning TS is to change the way you write code to make it easier to type. You have to make decisions earlier in the process, and yes, there is usually more time spent writing code initially, but if done well, you can screen out a lot of bugs.
IMO these devs have the luxury of not using TS because they can expect the community to provide the types for them.
I think this is a correct answer. TS is just a different language happened to interop js easier than the others.
This is false though, but admittedly not documented well.
Additionally, many of these devs are arguably masters at vanilla JavaScript. Some learned JS before modern features became available. They probably don’t need ES5 features to be productive, let alone the newer features or for that matter TypeScript.
The frustration is that they would probably benefit from using TypeScript in the long run.
I resisted learning TypeScript because it felt like coding with handcuffs on.
I was sold on it when I realized how much easier the handcuffs make it to accept code contributions. I've internalized TS enough that I still get to flow state on my own code. Whole categories of rookie mistakes no longer interrupt my blissful concentration, because they are caught by tooling before making it in to a pull request.
That being said, as a Svelte user, I really wish Rich would stop dragging his feet on Typescript as much as he does (no TS in markup is a huge bummer). I can’t complain too much though.. the Svelte Compiler is a magnificent beast and I couldn’t write it let alone contribute to it in a meaningful way. If leaving Typescript to the other maintainers helps him be more productive, so be it.
2. Use a modern target, my transpiled code is 1:1.
3. You can use JSDoc type annotations, I use this for some projects.
4. TS works well in functional code bases. If you prefer JavaScript's dynamics, expect pain.
5. You can also use Flow.
6. Your sample size is 3
3. Yeah people do that but then the vibe of "language" is gone, just a linter.
5. No jobs.
4. That's why it's not a good idea to coerce dynamic type lang, it barely ends well.
1. Same as 3.
2. Yes
2. Harder to grok code (spaghetti)
3. I don’t want to give Microsoft any more leverage over the development ecosystem
4. TS will likely go the way of CoffeeScript eventually
5. TS is massively complex because of the difficulty of typing JS, I’d much rather use a language designed from the start as a strongly typed language.
6. The types are removed after compilation, so they’re only helpful during development.
However, I do like to add JSDoc types and run the Typescript compiler to check things and generate types for TS users.
[SvelteKit] (official Svelte framework) uses TypeScript quite a bit.
First, the internal code was ported to TypeScript, then DX for TypeScript was added. The official template supports JSDoc TS (default), TypeScript, or no typing.
I think another community member added TS support, and Rich said he couldn't have done it by himself. (Or maybe that was regarding the VS Code TS support tooling.)
[SvelteKit]: https://kit.svelte.dev/
Essentially, TS feels like training wheels for small codebases and red tape for large codebases. I do feel it helps for large codebases where someone might not be familiar with everything but reading the code works way better than types. If someone can not understand the code then that means: 1) it is not documented correctly, 2) the person needs more instruction/tutelage, 3) it is probably incorrectly implemented or 4) something more clever.