Obtaining the return type of a function

前端 未结 7 2326
既然无缘
既然无缘 2020-12-02 08:56

I have the following function:

function test(): number {
    return 42;
}

I can obtain the type of the function by using typeof

7条回答
  •  遥遥无期
    2020-12-02 09:40

    There isn't a way to do this (see https://github.com/Microsoft/TypeScript/issues/6606 for the work item tracking adding this).

    A common workaround is write something like:

    var dummy = false && test();
    type t2 = typeof dummy;
    

提交回复
热议问题