12/11/2023 0 Comments PermutationSo let's tie this back into distributing over never. Minor Primer on Distributive Conditional Types (Click me)īasically, TypeScript sees this: T extends U ? X : Y and when provided with a type argument where T = 'A' | 'B' it gets "distributed" and resolved as (A extends U ? X : Y) | (B extends U ? X : Y). TypeScript does an interesting thing when unpacking generics into conditionals: it distributes them. Well, it turns out T extends never doesn't work when T = never but not because of anything to do with the conditional. " boolean is not assignable to parameter of type never"? But.the parameter should only be true | false right? If T extends never it should be true and if T extends never is not the case, it should be false, right? I totally stole the idea of the example I'm explaining hereĪnywho, here is what we might create on our first pass:ĪssertNever ( true ) // ^^^^ TS Error (2345) // Argument of type 'boolean' is not assignable to parameter of type 'never'. Just roll with it, OK? Wanna know a juicy secret? (Click me) You might want to use it to check some weird types you are building or something. This function would be used for checking to make sure a type is.well. Imagine you want to make a function called: assertNever. It makes sense eventually, so just bear with me. That my friends is a "feature" of TypeScript. What in the bowels of 16-bit hell is that? Glad you asked. #614 (comment) Excellent Chinese translation by (Click me) Don't worry I'll break it all down weird piece, by weird piece □ TLDR by (Click me) : never type Permuted = Permutation // |
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |