setError(e.message) 报错 看了老师您回复的其他同学的 没有看懂。。。。。
来源:4-6 【副作用钩子】useEffect 使用指南

慕仙2155826
2022-05-06
写回答
1回答
-
hello 同学,你现在看到的是typescript 4.0的写法,typescript 4.0引入了对try catch类型处理的增强。
下面是一个try catch的例子
try { throw new Error('foo'); } catch (err: unknown) { if (err instanceof Error) { return { message: `Things exploded (${err.message})`}; } }
如果你嫌麻烦,也可以直接把err转化为any类型(当然最好不要这样做)。
目前正在处理课程的更新,这部分内容也会使用最新的版本的ts代码
012022-05-10
相似问题