….gasp
And that was never a goal for it. But it is still pretty freaking awesome.
While helping around with TypeScript I quite commonly come across people complaining about some of the fiddly syntax. A great example is destructuring parameters:
See the duplication of `x` and `y`. That’s because a key thing that makes TypeScript great is that valid JavaScript is valid TypeScript. TypeScript is pretty much forced to have the type annotation after the destructuring parameter. This is because TypeScript needs to support renamed destructured arguments which is a JavaScript thing. Below example renames the property x from the object passed into a local name `xLocal` (Note this is just plain JavaScript ES6):
So standard intuition of a new TypeScript developer of `x:TypeAnnotation` breaks in this example.
Sometimes people just want a consistent syntax e.g. consider the Object Literal Syntax is inconsistent with normal equal assignment:
Again if TypeScript made it different from JavaScript it would be a pretty awful idea.
People come to TypeScript and they complain about its imperfections which I can sympathize with. However these complaints are mostly against JavaScript. Adding a new syntax to a language is something that needs to be done carefully, but even more carefully if you want to make the language a strict super-set of another. If JavaScript is a language that you need to work with … TypeScript is the best type safe option you have 🌹