[英]createStore with strict typescript
import { createStore } from "redux";
import * as storage from "redux-storage";
const reducer = storage.reducer((state, action) => ({}));
const store = createStore(reducer, {});
當使用上面的代碼並strict
啟用typescript時,我收到以下警告:
[ts] Argument of type 'Reducer<{}>' is not assignable to parameter of type 'Reducer<{}, AnyAction>'.
Types of parameters 'state' and 'state' are incompatible.
Type '{} | undefined' is not assignable to type '{}'.
Type 'undefined' is not assignable to type '{}'.
我理解TS嚴格模式是什么,但我不明白為什么它將我的狀態解釋為可能undefined
我能做錯什么? 或者,我怎么可能對付沒有做一些懶惰像誤差as any
?
提供的狀態值可能未定義。 強制它應該解決你的問題。 例如
const reducer = storage.reducer((state = {}, action) => ({}));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.