logoalt Hacker News

embedding-shapeyesterday at 4:20 PM1 replyview on HN

Typed Python vs untyped Python is literally the same as TS vs JS, don't let others fool you into thinking somehow it's different.

> TypeScript helps paper over like 90% of the holes in JavaScript

Always kind of baffles me when people say this, how are you actually programming where 90% of the errors/bugs you have are related to types and other things TS addresses? I must be doing something very different when writing JS because while those things happen sometime (once or twice a year maybe?), 90% of the issues I have while programming are domain/logic bugs, and wouldn't be solved by TS in any way.


Replies

shadowgovtyesterday at 7:05 PM

I mean, I'm one of the fools who would fool you into thinking it's different, since I use all four languages. ;)

I can just skip the mypy run if I want to do untyped Python. I can't skip adding types if I'm writing TypeScript in most contexts; it's not valid TypeScript syntax. Conversely, I can't add types to JavaScript; it's not valid JavaScript syntax (jsdoc tags and running a static checker over that being a different subject, and more akin to the Python situation).

> how are you actually programming where 90% of the errors/bugs you have are related to types and other things TS addresses

It's the things in the "wat" video. JavaScript, in general, errs on the side of giving you some answer when you try and do something very unusual with types (like add a boolean to a number or a string to an array) over taking a runtime error. TypeScript will fail to typecheck in most of the places where those operations are techincally correct but surprising as hell in the wrong way unless you explicitly coerce the types to match up.