Last active
September 27, 2022 20:20
-
-
Save danieldietrich/c0a21d28a52b05f307e4a456533de287 to your computer and use it in GitHub Desktop.
Revisions
-
danieldietrich revised this gist
Sep 27, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ β Solved distribution: ```ts DistributiveConditionalType<never, 1> = never // never is the empty union, it distributes to nothing and therefore the type resolves to never ``` β Solved the expanded type: -
danieldietrich revised this gist
Sep 27, 2022 . 3 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.File renamed without changes. -
danieldietrich revised this gist
Sep 27, 2022 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ β Solved distribution: ```ts DistributiveConditionalType<never, 1> // why resolved as π never? = never // never is the empty union, it distributes to nothing and therefore resolves to never. ``` β Solved the expanded type: ```ts (never) extends (1) ? true : false = true // no type extends anything by definition ``` -
danieldietrich created this gist
Sep 27, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ **Def.** A conditional type with a checked _naked type parameter_ T is called _distributive conditional types_. Example: ```ts // given U, X and Y type DistributiveConditionalType<T> = T extends U ? X : Y; ``` Distributive conditional types are automatically distributed over union types during instantiation. Example: ```ts DistributiveConditionalType<A | B | C> = (A | B | C) extends U ? X : Y = (A extends U ? X : Y) | (B extends U ? X : Y) | (C extends U ? X : Y) ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ Given ```ts type DistributiveConditionalType<T1, T2> = T1 extends T2 ? true : false; ``` Then ```ts DistributiveConditionalType<never, 1> // why resolved as π never? = (never) extends (1) ? true : false // why resolved as π true? = ??? // How does the π distribution look like? ```