【发布时间】:2019-09-30 21:56:35
【问题描述】:
我正在关注TypeScript-React-Starter tutorial,并在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.
Issue #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'.
问题已关闭,但其他人也遇到了同样的问题。
如何创建我的商店?
【问题讨论】:
标签: reactjs typescript npm redux react-redux