私は最初の反応を開発しようとしています& reduxとtypescriptの例ですが、私はアクションの宣言に固執しています。 typescriptコンパイラは同じエラーを何度も何度もスローします。redux-actions Typescriptはアクションを宣言します
多分私は概念の何かを忘れました。
コードはthisチュートリアルに基づいています。
は
graphActions.ts
/// <reference path="../../../typings/index.d.ts"/>
import { createAction, Action } from 'redux-actions';
import * as _ from 'lodash';
import {IGraphObject} from "../components/graph/GraphObject";
import {Graph} from "../models/Graph";
import {ADD_GRAPH} from "../constants/ActionTypes";
const addGraph = createAction<Graph>(
ADD_GRAPH,
(graph: IGraphObject) => ({graphObject: graph})
);
export {
addGraph
}
Graph.ts
import {IGraphObject} from "../components/graph/GraphObject";
export type Graph = {
id?: number;
graphObject: IGraphObject
}
GraphObject.ts
export interface IGraphObject {
id?: number;
graphConfig: IGraphConfig;
graphInstance: any;
initGraph(container: HTMLElement);
addShape(shape: ICustomShapeElement);
}
typescriptですコンパイラがスロー任意のヘルプについて喜んでいるだろう
(11,5): error TS2345: Argument of type '(graph: IGraphObject) => { graphObject: IGraphObject; }' is not assignable to parameter of type '(...args: { id?: number; graphObject: IGraphObject; }[]) => { id?: number; graphObject: IGraphObj...'.
Types of parameters 'graph' and 'args' are incompatible.
Type '{ id?: number; graphObject: IGraphObject; }' is not assignable to type 'IGraphObject'.
Property 'graphConfig' is missing in type '{ id?: number; graphObject: IGraphObject; }'.
Reduxのストアのグラフは、より複雑なグラフのインスタンスを含むべきである単純型です。 私が達成したいのは:ユーザーがaddGraphボタンをクリック=> graphObjectInstanceを作成し、それをreduxストアにディスパッチします。 doToを文字列から作成しなければならない例のように、 –
私は正しく理解すれば、それはaddGraph = createActionであるはずです。 –
Daniel
解決しました。 redux-actionsのindex.d.tsを見れば私は助けになりました。 'constのaddGraph = createAction' –