TypeScript: why?

Natarajan Santhosh
1 min readSep 7, 2023

--

Write in typescript vs JavaScript with types :)

I’m sure there’s much to be said about the weaknesses of TypeScript’s concepts and implementation but in my experience every time I fought the typing system I came to realize my modeling was bad. I was using the wrong data structure or algorithm for the job.

I think strong typing is bit like insurance. There are situations where you can just wing it take the risk. But there are others where you shouldn’t and you may end up paying double later on.

Plus TypeScript was designed to be flexible enough that it could be applied to existing JavaScript codebases, which especially in the old days often employed.. let’s say “creative” solutions. If your code employs such “creative” data models (even if you aren’t using a strongly typed language, all code at least has implicit data modeling) that you can’t make them fit in TypeScript, I’d say there’s likely a better way to model your data.

Yeah, I’m working on a codebase that has over 1M lines of code, namespaces instead of modules, and that is roughly as old as the JavaScript language itself.

For every headache that TypeScript has brought me, and it has given me plenty, it has saved me more. It has enabled significant refactors, and I am constantly wishing that old JS code had types because I often have no idea what existing functions actually return without literally building, running, and inspecting the output.

--

--

No responses yet