by rattray · 4y ago · 0 comments
Choosing to use JS without TS at this point has become a dogmatic statement of purism that, while beautiful in a sense, is so unpragmatic as to appear a little foolish.
It's like insisting on using the pre-electronics version of a powerful, dangerous machine even though the new version gives you just as much control, greater precision, and much better safety, because of a romantic notion of purity in the way things should be done. Admirable and not at the same time.
Assuming everyone should use TypeScript just because you happen to like it over JavaScript seems crazy. But I guess that makes me seem crazy to you, so here we are in a circle...
TypeScript seems to have entered the same hype cycle as Rust (if it didn't do it before Rust) where people seem to think that everything written in X should actually be written in Y instead (C/C++ => Rust and JavaScript/Any compile to JS => TypeScript). Doesn't mean every project have to follow that though.
I certainly would never take a job in a pure JS shop.
Could you please provide a list of these tradeoffs?
This statement makes no sense in two ways and shows you're not as accustomed to the problems at hand as you'd perhaps like to be. First, eslint is a developer tool and not intended to run in the browser. Second, you generally do not distribute typescript code but compiled js to target platforms.
> TypeScript seems to have entered the same hype cycle as Rust (if it didn't do it before Rust) where people seem to think that everything written in X should actually be written in Y instead (C/C++ => Rust and JavaScript/Any compile to JS => TypeScript). Doesn't mean every project have to follow that though.
No, TypeScript is a superset of JavaScript that can be enabled with little cost for the gigantic benefit of bringing type safety to a language which people have mocked for its unsafety for decades.
I really wish people on HN would hold back a little with their contrarian purism at all cost.
from the linked article: "Yes, that means an officially supported browser version!"
TypeScript transpilation is easy and fast. You can emit JS even when there are type errors, and use tsc as just a type-checker while using esbuild to strip types from JS. Performance is not an issue in practice and the benefits are pretty far reaching.
> Runtime agnostic. ESLint should be able to run in any runtime, whether Node.js, Deno, the browser, or other. Runtime agnostic. ESLint should be able to run in any runtime, whether Node.js, Deno, the browser, or other. […]
Since the new ESLint is going to be highly modular, TS would shine in defining these modules' interfaces in a robust way. Whether to use TS deeper down, or whether to enforce the use of TS across the codebase, is another question. Prototyping is often easier and faster with plain JS, while typing well-defined parts later may be helpful for maintenance purposes.
I disagree, especially in the realm of AST-crawling, that having type hints in the IDE has been extremely beneficial in moving fast.
Type-level refactoring tools don't seem to be very powerful at the moment, too; without them, you can end up with some legwork when you change a design decision (a frequent thing while prototyping), even if you carefully aliased every type (which is legwork in its own right, because trivial cases like 2-tuples are plentiful).
Fortunately, TS allows you to gradually type your code, and rely on inference in many cases (not as much as Haskell, but still).
Bonus points if it comes in notebook form so you get a nice convenient run button, a solid multiline text editor, and markdown-powered persistence format.
Thankfully, this already exists: https://marketplace.visualstudio.com/items?itemName=jakearl.... . And it supports every language your shell does!
(I made it)
https://www.typescriptlang.org/docs/handbook/jsdoc-supported...
People, if you must be religious about a programming language, at least find a more enthralling god than a JS superset!
> ESM with type checking. I don't want to rewrite in TypeScript, because I believe the core of ESLint should be vanilla JS, but I do think rewriting from scratch allows us to write in ESM and also use tsc with JSDoc comments to type check the project. This includes publishing type definitions in the packages.
This is such a heated debate, and so many posts here are just simply wrong about the capabilities of using TypeScript as a type checkers.
A statically typed code base is a primary goal of the author, they simply pick to do it using JavaScript and annotating the types in JSDoc comments, using TypeScript only as the static type checker, which is an available—and well supported—option in TypeScript.
> Choosing to use JS without TS at this point has become a dogmatic statement of purism that, while beautiful in a sense, is so unpragmatic as to appear a little foolish.
You’re parent is simply just wrong here, and it is quite frustrating how many posts here simply take up this talking point and repeat it.
I disagree. The lesson learned from a decade of js tooling is performance issues.
That is why you see more and more js tooling rewritten in rust or other fast languages.
This is GOOD for js development, in the sense you end up with better faster more powerful tooling.
Now whether you use JS at all is a completely different point, but I think the parent was making a point about TS > JS, than TS > other languages.
The main exceptions are enums, and decorators, both of which perform straightforward transformations. My understanding is that adding new such features are forbidden as the TypeScript team considers them to be historical mistakes. If new syntax is added in the future is should be such that it can be mechanically stripped, leaving the obvious underlying JS behind.
There also exist some historical features like namespaces or const enums that have long been considered essentially deprecated by the team (not marked as such in the documentation, as there are no plans to actually delete support for them, but they won't work correctly in isolatedModules mode for example). In practice those features are not used in new codebases since project templates will be configured with isolatedModules enabled.
This gets a bit more complicated in some setups because the typescript compiler can also transpile modern JS/TS code to older versions, doing a similar job to Babel, but this doesn't have to be the case, and in practice this tends to be fairly orthogonal to the question of Typescript: you can compile to older versions regardless of whether you use Typescript, and you can use Typescript regardless of whether you compile to older versions.
So in practice, there will be no difference between a Typescript program and an equivalent idiomatic Javascript version, because Typescript is just Javascript with syntax for type hints.
The advocacy for Typescript is for type safety. Using Rust hits that same benefit.
opentelemetry.js is already an architectural nightmare (clearly built by people who use J2EE), but the fact that it's Typescript makes it ten times worse because I can't set breakpoints. I have to step all the way in every single time. Through layer after layer of delegation. So much delegation they had to pull out a thesaurus to name things.
JSDoc can do a lot of the things that Typescript does. Use it.
This sounds like everyone wins except the people who are overly-dogmatic about TS.
What about Deno or people using it in web-only contexts?
If they use ES-compliant modules, a build step isn't even required.
Once again, it's not that they don't have types, but the TS fanboys are now complaining that it's "not the right types".
But if you're building developer tools or libraries and want the output to be optimized for the end-user, introducing a middleman like tsc or esbuild can have tradeoffs. This is likely what the ESLint team considered.
It doesn't seem that performance was the driving factor, but the ability to keep code idiomatic?
https://docs.google.com/document/u/0/d/1_WvwHl7BXUPmoiSeD8G8...
> Incremental compile time when changing files in cli/js takes minutes. This is crushingly slow and painful to modify.
> The typescript organization/structure that we're using in cli/js is creating runtime performance problems.
Either way, my point is that there are very practical non-dogmatic reasons to use JS over TS.
The goal is type safe code, and there are multiple paths that get you to that goal. Pretending that TS is the only, golden path and everyone else is hopelessly wrong -requiring hyperbole to mock even- suggests having lost sight of the actual goal itself.
Every bug to to ever hit production has
* passed all manual testing
* passed all unit tests
* passed the type checker
What isn't helpful is the the notion that types replace testing. Either manual testing or unit/functional/generative testing. It isn't "safer" at all, it does speed up development by catching the simple bugs so the run edit compile loop is less. If you're saying "my code compiles then it's works", I don't buy it.
I'm glad that you agree type checkers help avoid error prone and expensive manual testing work.
> What isn't helpful is the the notion that types replace testing.
Types are a type of testing. They are another tool in the toolbox for writing correct programs.
Or been ignored. It happens.
> passed all unit tests
If they have been written at all. And every bugfix should come with a regression test.
> passed the type checker
If it hasn't been disabled. And I would expect that a bug that could be fixed with better typing would include making types more restrictive when necessary.
Unfortunately, tools like testing and types are seen in two conflicting ways. Some people embrace them and see that they can use them to write better code with less bugs. Others see them as obstacles that have been placed in their way due to the additional learning curve.
But what bugs did you not see hit production because these eliminated it?
for real, it's less the hassle.