我正在跟随TypeScript-React-Starter教程,并在src/index.tsx
中创建一个存储。根据教程内容:
const store = createStore<StoreState>(enthusiasm, {
enthusiasmLevel: 1,
languageName: 'I\'m fluent in Math and Klingon'
});
产生错误
Expected 4 type arguments, but got 1.
问题 #136 建议使用
import { EnthusiasmAction } from './actions/index';
const store = createStore<StoreState, EnthusiasmAction, any, any>(enthusiasm, {
enthusiasmLevel: 1,
languageName: 'I\'m fluent in Math and Klingon'
});
除了其他类似的解决方案外,但这会产生另一个错误:
Argument of type '(state: StoreState, action: EnthusiasmAction) => StoreState' is not assignable to parameter of type 'Reducer<StoreState, EnthusiasmAction>'.
Types of parameters 'state' and 'state' are incompatible.
Type 'StoreState | undefined' is not assignable to type 'StoreState'.
Type 'undefined' is not assignable to type 'StoreState'.
问题已经关闭,然而其他人之后也遇到了同样的问题。
如何创建我的商店?