I don't know why distribution affect to problems.
Created
January 12, 2021 01:56
-
-
Save ellemedit/ea165b79f92ad9047f1baa66e9a02e5c to your computer and use it in GitHub Desktop.
Generic distribution problem in TypeScript
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 characters
type Test1<T> = { | |
[K in keyof T]: | |
T[K] extends string ? { string: true } : | |
T[K] extends number ? { number: true } : | |
T[K] extends object ? Test1<T[K]> : | |
never; | |
}; | |
type Test3<T> = T extends T ? { | |
[K in keyof T]: | |
T[K] extends string ? { string: true } : | |
T[K] extends number ? { number: true } : | |
T[K] extends object ? Test3<T[K]> : | |
never; | |
} : never; | |
function A<T extends { a: string }>() { | |
let a: Test1<T> = null as any; | |
let b: Test1<{a:string}> = null as any; | |
a.a.string; // ERROR: any, Property 'string' does not exist on type 'T["a"] extends string ? { string: true; } : T["a"] extends number ? { number: true; } : T["a"] extends object ? Test1<T["a"]> : never'.(2339) | |
b.a.string; | |
let e: Test3<T> = null as any; | |
let f: Test3<{a:string}> = null as any; | |
e.a.string; | |
f.a.string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment