检索 return 类型的函数 w/o 调用函数
Retrieve return type of function w/o calling the function
假设我在 TypeScript 中有这样一个函数:
export const foo = function(){
return {
a: 1,
b: true,
c: 'bar'
}
};
如果我将此函数导入另一个文件:
import {foo} from './foobar';
我的问题是 - 有没有办法得到 return 类型的 foo
实际上没有 呼叫 foo
?
现在可以使用 Typescript 2.8
let foo = function() {
return {
a: 1,
b: true,
c: 'bar'
}
};
type ComplexObj = ReturnType<typeof foo>; // {a: number, b: boolean, c: string}
假设我在 TypeScript 中有这样一个函数:
export const foo = function(){
return {
a: 1,
b: true,
c: 'bar'
}
};
如果我将此函数导入另一个文件:
import {foo} from './foobar';
我的问题是 - 有没有办法得到 return 类型的 foo
实际上没有 呼叫 foo
?
现在可以使用 Typescript 2.8
let foo = function() {
return {
a: 1,
b: true,
c: 'bar'
}
};
type ComplexObj = ReturnType<typeof foo>; // {a: number, b: boolean, c: string}