【发布时间】:2021-09-16 18:42:19
【问题描述】:
const destructPromise = <TResult>(promise: Promise<TResult>) => {
return promise.then(data => [data, null]).catch(err => [null, err]);
};
const test = async () => Promise.resolve({ a: 1 });
const fun = async () => {
const [a, b] = await destructPromise(test()); // Why in this example the types of variables 'a' and 'b' are inferred as any?
};
为什么在这个例子中变量 'a' 和 'b' 的类型被推断为 any?
【问题讨论】:
-
您希望该类型解析为 TResult 吗?
-
我希望至少类型 'a' 将被推断为 TResult |空
-
@CaptainChaos 两位船长:D