DEV Community

Discussion on: TypeScript is a waste of time. Change my mind.

Collapse
 
wmertens profile image
Wout Mertens

Types are just a hack to give hints to your compiler.

A correct program is still correct without types.

Types are like drawing lines in the sand and saying "all values of this item lie within these lines". The typing system lets you define those lines with varying accuracy.

There are languages where you can say that a function will get arrays of length n and m, and it will return an array of length n+m. But why stop there? After all, each element could be an algebraic transform of the input, let's type number -> 2*number. It gets a bit silly imho.

In the end, types give information that code analysis should be able to get automatically. Given infinite time. Therefore, they are duplicate information, and should only be used where the compiler struggles.

I would be happy with mostly untyped TypeScript. In fact, that's what vscode already provides, thanks to context aware completion and typed libraries :)

The only thing I sometimes miss is something telling me I forgot to await a Promise (although sometimes that's exactly what I want to do).

Collapse
 
stereobooster profile image
stereobooster

I have response for

Types are just a hack to give hints to your compiler.

here (section Are types only required for the compiler?)

Collapse
 
bigredmonsteruk profile image
Big Red Monster

"I would be happy with mostly untyped TypeScript. In fact, that's what vscode already provides, thanks to context aware completion and typed libraries :)"

untyped TypeScript? That would be ESNext surely? Except not as good because it wouldn't have the newer ES features and you'd have to have a compile step.
Also other IDEs provide context aware competion for plain JS (IntelliJ, Webstorm, Atom + tern)