Skip to content

Instantly share code, notes, and snippets.

@chenyong
Created May 20, 2019 06:48
Show Gist options
  • Save chenyong/2b645fe898546248912d6a36f4a08bfc to your computer and use it in GitHub Desktop.
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.
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