对象是类型'未知'关于承诺的打字稿
我有一个简单的函数,该功能作为参数的函数并返回一个新功能。当调用返回的函数红波信息:const响应:未知对象类型为'
export function fetchCount(amount: number) {
return new Promise(resolve => setTimeout(() => resolve({ data: amount }), 500));
}
export const incrementAsync = createAsyncThunk('counter/fetchCount', async (amount: number) => {
const response = await fetchCount(amount);
return response.data; // red wave info under response
});
unknown.ts(2571)时,我得到的对象是“未知”类型
I have a simple function that takes a function as it's argument and returns a new function. I get Object is of type 'unknown' when calling the returned function
export function fetchCount(amount: number) {
return new Promise(resolve => setTimeout(() => resolve({ data: amount }), 500));
}
export const incrementAsync = createAsyncThunk('counter/fetchCount', async (amount: number) => {
const response = await fetchCount(amount);
return response.data; // red wave info under response
});
red wave info:const response: unknown Object is of type 'unknown'.ts(2571)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Promise< t>
是一种通用类型,在您的情况下不能推断该类型,因此您需要提供该通用类型参数:Promise<T>
is a generic type and the type cannot be inferred in your case, so you'll need to provide that generic type argument: