Are there (m)any other languages with type systems as flexible and powerful as Typescript's?
I believe that typescript type system is so flexible, powerful and complex just because it had to be adapted and built around the shortcomings and limitation of javascript. It makes no sense to have something like it if you build a language from the ground up (or if you could just scrap backward compatibility in a bad designed one)
Extreme explorations of TypeScript's type system
51–60 of 64 posts
Re: Extreme explorations of TypeScript's type system
#52Are there (m)any other languages with type systems as flexible and powerful as Typescript's?
Yes there are. For instance Idris ( https://www.idris-lang.org/ ) has a way more powerful typesystem than Typescript. If you are looking for more practical and less academic languages, then Scala would be one of the languages that technically has a more powerful/generalized typesystem but at the same time is harder to use compared to Typescript's and cannot do some things that Typescript can do.
> In type-driven development, types are tools for constructing programs. We treat the type as the plan for a program, and use the compiler and type checker as our assistant, guiding us to a complete program that satisfies the type. The more expressive the type is that we give up front, the more confidence we can have that the resulting program will be correct.
Great stuff.
Re: Extreme explorations of TypeScript's type system
#53You can do some truly silly things with sufficiently ridiculous uses of typescript. I built a typecheck-time spell checker[0] in it such that: import { ValidWords } from "./spellcheck"; // Typechecks cleanly: const result: ValidWords = "valid"; // Throws a type error const result: ValidWords = "valid"; [0] https://github.com/kkuchta/TSpell
1: https://github.com/kkuchta/css-only-chat 2: https://github.com/kkuchta/tabdb
Re: Extreme explorations of TypeScript's type system
#54> If you do find a need to use type operations, please—for the sake of any developer who has to read your code, including a future you—try to keep them to a minimum if possible. Use readable names that help readers understand the code as they read it. Leave descriptive comments for anything you think future readers might struggle with. Also, as you start getting complicated logic in your types, you need to test your…
I lost it when at my previous job I found a 20 multiline super complex type defined by another dev, asked him to describe it because I was in a tight deadline and had not time to parse whatever he was defining. He starts with "it's pretty simple" and then used like 10 minutes to describe me what he meant while writing on paper the various pieces getting confused two times. At the end of the day it could be simplified…
sorry about that
Re: Extreme explorations of TypeScript's type system
#55Are there (m)any other languages with type systems as flexible and powerful as Typescript's?
I believe that typescript type system is so flexible, powerful and complex just because it had to be adapted and built around the shortcomings and limitation of javascript. It makes no sense to have something like it if you build a language from the ground up (or if you could just scrap backward compatibility in a bad designed one)
This isn't because of the shortcomings of JavaScript, it's because of the shortcomings of simple type systems.
Simple type systems (like those of Java or Go) restrict the kinds of programs you can easily write while satisfying the type checker. Normally, the alternative is resorting to languages without static type checkers, like JavaScript.
TypeScript allows mostly idiomatic JavaScript even with complex runtime invariants to be given quite accurate types at compile time. It has features I miss all the time in Java.
Re: Extreme explorations of TypeScript's type system
#56Re: Extreme explorations of TypeScript's type system
#57Does anybody have a document that describes all type constructions in typescript? The "official" handbook doesn't seem complete. Some time ago, I tried to use tuples in types, but I couldn't figure out the correct syntax. I found some vaguely similar examples on stackoverflow, so it seems some people did get that information.
Re: Extreme explorations of TypeScript's type system
#58Re: Extreme explorations of TypeScript's type system
#59Does anybody have a document that describes all type constructions in typescript? The "official" handbook doesn't seem complete. Some time ago, I tried to use tuples in types, but I couldn't figure out the correct syntax. I found some vaguely similar examples on stackoverflow, so it seems some people did get that information.
It helps to read the release notes to keep up to date. https://www.typescriptlang.org/docs/handbook/release-notes/t...
Re: Extreme explorations of TypeScript's type system
#60[0]: https://effectivetypescript.com/2022/02/25/gentips-4-display...