Hacker News new | ask | show | jobs
by s6af7ygt 594 days ago
I dislike TypeScript, and I feel it's mostly fake. There are plenty of ways to accidentally bypass the "type system" and do stuff that should be illegal in a statically typed language but work because there's JavaScript underneath. I feel TypeScript adds extra cognitive load that isn't necessary and isn't really adding much value. JavaScript is simple, easy, and works well. I wish more people would invest in learning to write better JavaScript, than to have the flaky facade on top of it.

Then again, I'm not a front-end dev, I just do hobby projects with JS.

2 comments

If you are mostly writing JS to enhance a web page, I would say it is good enough.

I recently to wrote an application that interfaces with a non-trivial Json API which returns many different data types.

I defined all the interfaces produced by the API in TS, and once this was done the app practically wrote itself with hardly any surprises.

With the data structures documented, the logic is concise and readable. To me, this is "better Javascript".

Of course, if the API changes, randomly all the types are a lie... it would be nice if I could reuse the types to do some runtime validation of fetch results, pydantic-style.

TS is fake in the sense that so many developers believe it to be more powerful than it actually is. If you use `any` at any point then you have virtually no guarantees. It also only helps partially when you don't validate data during runtime. Unfortunately, I've seen many developers write code as if no checks are needed during runtime because of Typescript, yet their application receives data structures from the outside.