import { ValidWords } from "./spellcheck";
// Typechecks cleanly:
const result: ValidWords = "valid";
// Throws a type error
const result: ValidWords = "valid";
[0] https://github.com/kkuchta/TSpellExtreme explorations of TypeScript's type system
21–30 of 64 posts
Re: Extreme explorations of TypeScript's type system
#22When this happens, typescript language integration (like in vs code or sublime text) will suddenly fall over and stop working correctly, and it'll be near impossible to figure that out too.
Our build uses rollup to invoke tsc and as it happens their profiling system doesn't actually measure how long tsc takes to run - the time is unaccounted :) So in general, be aware that 'typescript is taking a long time to compile' is a blind spot for this whole ecosystem and if you hit it you're going to have to work hard to fix it.
Re: Extreme explorations of TypeScript's type system
#23You 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
Re: Extreme explorations of TypeScript's type system
#24Are there (m)any other languages with type systems as flexible and powerful as Typescript's?
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.
Re: Extreme explorations of TypeScript's type system
#25You 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
So does spellcheck contain a gigantic array of the English language?
Re: Extreme explorations of TypeScript's type system
#26To try and limit one's use of operations on types, as suggested in the article, is not really great advice in my opinion. Sure, you would not want to actually implement and use a VM in types, but distilling rules about a program into types and then deriving the actual interfaces and signatures from those rules with operations on types? That's quite powerful. TypeScript's type annotations are really a DSL embedded int…
So yeah, using discriminated unions, branded types, mapped types etc. in moderation can substantially reduce the surface area of errors - more so than other mainstream nominally typed languages. However, trying to model and prevent every invalid state at type level can lead to a serious drain in productivity. And, I am not really sure how to draw a line between.
Re: Extreme explorations of TypeScript's type system
#27You 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
Re: Extreme explorations of TypeScript's type system
#28Re: Extreme explorations of TypeScript's type system
#29This is a great list. I feel I'm only scratching the surface when it comes to Typescript, and it would be awesome to have a place where we can see advanced examples of Typescript usage like this. I've seen many projects where the typing is done so well that it can infer and include all the data I've fed into the TS-defined functions / classes, which is great for IDE autocompletion.
What are some of the projects have done typing that well?
Re: Extreme explorations of TypeScript's type system
#30You 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
So does spellcheck contain a gigantic array of the English language?
export type ValidWords = T extends ""
? "valid"
: T extends `the${infer Rest}` | `of${infer Rest}` | `and${infer Rest}` | ...