Created
May 20, 2019 06:48
-
-
Save chenyong/2b645fe898546248912d6a36f4a08bfc to your computer and use it in GitHub Desktop.
Infer return type from function parameter's type, based on https://dev.to/aexol/typescript-tutorial-infer-keyword-2cn This is far from satisfaction.
This file contains 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
let a ={ | |
b: { | |
c:1 | |
} | |
} | |
type A = typeof a | |
type F<T> = (x:T) => (T extends ((x:any)=> infer R) ? R: never) | |
let f = (select) => { | |
let result = select(a) | |
return result | |
} | |
let b = f((x:A) => { | |
return x.b | |
}) | |
let f1= (x:A) => { | |
return x.b.c; | |
} | |
type F1 = typeof f1; | |
let c = (f as F<F1>)(f1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment