[英]React TypeScript: Type 'string[]' is not assignable to type 'never[]'
When I save an array to a state and then read it back again I get the error Type 'string[]' is not assignable to type 'never[]' what is this all about?当我将数组保存到 state 然后再次读回时,我收到错误类型'string []'不可分配给类型'never []'这是什么意思?
I made a code sandbox here: https://codesandbox.io/s/affectionate-pasteur-kj5h0 where the code runs but shows the error in red underlines我在这里做了一个代码沙箱: https://codesandbox.io/s/affectionate-pasteur-kj5h0代码运行的地方,但用红色下划线显示错误
If you strongly type the generic param for useState you're all good如果您强烈键入 useState 的通用参数,那么一切都很好
const [state, setState] = useState<{ array1: string[] }>({ array1: [] });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.