且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在TypeScript中,是否有任何方法可以为函数本身键入函数返回值?

更新时间:2023-11-02 23:09:40

这可以通过条件类型

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

如果您对打字稿团队考虑的设计方案感到好奇,#6606 提供了一个很好的概述。

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