简体   繁体   English

React TypeScript:类型“string []”不可分配给类型“never []”

[英]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.

相关问题 在反应 typescript 中,类型“字符串”不可分配给类型“从不”并且类型“未知”不可分配给类型“从不”错误 - Type 'string' is not assignable to type 'never' and Type 'unknown' is not assignable to type 'never' error in react typescript React TypeScript:参数不可分配给“从不”类型的参数 - React TypeScript: Argument is not assignable to parameter of type 'never' Typescript React - 类型“字符串”不可分配给类型“外观” - Typescript React - Type 'string' is not assignable to type 'Appearance' Typescript/React-Native:'string | 类型的参数 null' 不可分配给“SetStateAction”类型的参数<never[]> '</never[]> - Typescript/React-Native: Argument of type 'string | null' is not assignable to parameter of type 'SetStateAction<never[]>' 与 Typescript 反应:“never[]”类型的参数不可分配给“StateProperties |”类型的参数 (() =&gt; 状态属性)' - React with Typescript: Argument of type 'never[]' is not assignable to parameter of type 'StateProperties | (() => StateProperties)' “文件”类型的参数不能分配给“从不”类型的参数。 与 TypeScript 反应 - Argument of type 'File' is not assignable to parameter of type 'never'. React with TypeScript reactjs + typescript 获取错误:类型“字符串”不可分配给类型“从不” - reactjs + typescript getting error: Type 'string' is not assignable to type 'never' 'string' 类型的参数不可分配给 typeScript 中的 'never' 类型的参数 - Argument of type 'string' is not assignable to parameter of type 'never' in typeScript 类型 'string[]' 不能分配给类型 'never[]' - Type 'string[]' is not assignable to type 'never[]' 打字稿:&#39;{translationSentences:从不[]; }&#39; 不可分配给类型为 &#39;never&#39; 的参数 - Typescript: '{ translatedSentences: never[]; }' is not assignable to parameter of type 'never'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM