2
有了这个例子:如何在流中获取函数的返回类型?
const myObj = {
test: true,
};
type MyType = typeof myObj;
const getValue =(): MyType => {
return myObj;
};
// how to do this??
type TheReturnType = getValue;
const nextObj: TheReturnType = {
test: false,
};
我想提取type
该函数将返回,这样我就可以重新使用该类型。我想不出来。上述不起作用。 typeof getValue
将返回该功能。
'getValue'返回一个'MyType'类型,所以你不能只将'nextObj'的类型设置为'MyType'?或者我误解了? – saadq
我不认为有办法做到这一点。也不能保证给定的函数只有一种类型。根据输入参数,许多函数具有不同的类型。 – loganfsmyth
@loganfsmyth许多可能的类型可以表示为这些类型的联合,这是一种单一的类型! –