3 ms·
TypeScript is a fundamentally different type system to most of the other mainstream languages (similarities exist only in typed racket and clojure's core.typed)
by spion 6y ago
TypeScript is a fundamentally different type system to most of the other mainstream languages (similarities exist only in typed racket and clojure's core.typed). The fundamental differences stem from the fact that it tries and succeeds to model almost all existing expressive dynamic JS constructs. The resulting different features include:
* structural instead of nominal types (i.e. if it walks like a duck and talks like a duck, it is a duck)
* mapped types let you transform object types into other object types: https://www.typescriptlang.org/docs/handbook/2/mapped-types.html https://www.typescriptlang.org/docs/handbook/2/mapped-types....
* conditional types let you apply conditional type transformations, and combine with mapped types to provide the equivalent of for comprehensions https://www.typescriptlang.org/docs/handbook/2/conditional-types.html https://www.typescriptlang.org/docs/handbook/2/conditional-t...
* template literal types let you generate dynamic string types on the fly, which you can use in various places including property names: https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html https://www.typescriptlang.org/docs/handbook/2/template-lite...
and so on.
It does have a learning curve, and the tooling is annoying to set up.
- pjmlp 6y agoWhich means that what looked like a nice WebIDL like in version 1.0 has grown to Haskell level language features by 4.2. I expect Template TypeScript and Liquid TypeScript are not far off. My enthusiasm for it has died, and I enjoy just doing a plain old <script src="myfile.mjs"/> on my own projects.