Hacker News new | ask | show | jobs
by ComputerGuru 1031 days ago
I agree with the main points in the post and certainly understand how they could push one in the direction that htmx has taken, but for me (and I posted a long comment along these lines as a reply in this thread elsewhere) the benefit of TypeScript isn't just the type safety but also that it forces you to explicitly provide more strongly-structured, parseable context info (regarding your intent in the codebase) that can be used to further empower static analysis tools (whether it's the TypeScript compiler or various linters à la eslint and co) to pick up on discrepancies between what the code is supposed to do and what the code does.

I view JS as a particularly unreliable language to build solid (as in dependable, consistent, coherent, and sound) projects in, and the various build tools are just ways to at least partially overcome those inherent shortcomings of the language. Transpiling from ESNext to ES5, merging disparate source components, etc are all just icing on the cake and not the real reason to use TypeScript (though I am surprised that the article talked about its ECMAScript version restrictions caused by IE11 support but didn't talk about how w/ TypeScript you can use language-level (not library-level) features such as the spread operator, for ... of, async/await, etc. and have them automatically converted/transpiled to functional equivalents that work on ES5 browsers).

Just look at how the various @typescript-eslint/* packages can supplant basic eslint rules, replacing them with more precise variants¹ by using the extra information provided by the TypeScript AST instead of just the info surfaced by the JavaScript AST.

¹ Let alone the existence of the hundreds of additional lints that are only possible for TypeScript codebases.

2 comments

If you are developing a large JS codebase then Typescript is probably a good idea. But the Hypermedia movement, including htmx, is saying don't build large JS codebases! If you send JSON down the wire then you need a large JS codebase to handle it. So don't send JSON down the wire! Send HTML instead, full pages or fragments as appropriate.
I think the goal is to never have to use or think about Javascript again.
It's not
I think I meant "the goal ought to be to never have to think about, let alone use, Javascript again."