3 ms·
As wonderfully absurd as this is, I learned more about TypeScript’s type system from this post than I have from its documentation. Entirely possible that PEBKA
by nkrisc 4y ago
As wonderfully absurd as this is, I learned more about TypeScript’s type system from this post than I have from its documentation.
Entirely possible that PEBKAC, but I’ve found TypeScript’s documentation to be on the worse end of the programming language documentation quality spectrum.
- wooly_bully 4y agoIt’s good for reference but not for discovery. If I already know the general concept (let’s say Template Literal Types) I can get good info on it, but if I start with a question like ‘Is there a way to make sure this string literal starts with “id_”?’ then I find it very hard to know. Random but this is what I’m finding GPT-4 best at: translating random questions into domain terminology + providing examples.
- iudqnolq 4y agomaybe this is just an issue with me but I've not found any way to search the docs. the only thing Google seems to index is the release notes, and going backwards from the release notes to guess the appropriate section of the docs that will explain that concept is really annoying.
- nkrisc 4y agoI can’t even find basic type definitions for standard JS functions. I have to type the function in my IDE and then open the type definition from there. So it works, I guess, but that’s not really how I want to work.
- DangitBobby 4y agoIt's not just you. To learn how to express more advanced types (or learn whether they are even possible to express), I've had to Google, read source code, or scan random medium articles and blogs from tech companies. Rarely have I learned anything new from the TS docs.
- nkrisc 4y agoI learned more from this type definition than anything I’ve ever read about TypeScript’s type system before: interface add extends F { out: this['args'] extends [infer a, infer b] ? a extends Zero ? b : a extends Suc<infer n> ? Suc<apply<add, [n, b]>> : never : never }