![](/img/trans.png)
[英]Type 'string' is not assignable to type 'never' and Type 'unknown' is not assignable to type 'never' error in react typescript
[英]React TypeScript: Type 'string[]' is not assignable to type 'never[]'
當我將數組保存到 state 然后再次讀回時,我收到錯誤類型'string []'不可分配給類型'never []'這是什么意思?
我在這里做了一個代碼沙箱: https://codesandbox.io/s/affectionate-pasteur-kj5h0代碼運行的地方,但用紅色下划線顯示錯誤
如果您強烈鍵入 useState 的通用參數,那么一切都很好
const [state, setState] = useState<{ array1: string[] }>({ array1: [] });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.