In TypeScript, is there any method to type function return values to the function itself?

后端 未结 1 1614
夕颜
夕颜 2021-01-17 06:42

For the last week, I\'ve been researching how it could be possible to type function return values to the funtion itself in TypeScript.

What is hard to me is types ar

相关标签:
1条回答
  • 2021-01-17 07:20

    This can be accomplished with conditional types introduced in typescript 2.8:

    let someFunction: () => String;
    let x : ReturnType<typeof someFunction>;
    

    In case you are curious about the design alternatives the typescript team considered, the discussion in #6606 provides a good overview.

    0 讨论(0)
提交回复
热议问题