2017-12-25 30 views
0

私は、create-react-app --scripts-version = react-scripts-tsコマンドを使用してtypescriptサポートを持つ反応アプリケーションを作成しようとしています。typescript内のコンストラクタ()内でsuper()を呼び出せません

私はこのエラーを見続ける:

(23,15): error TS2345: Argument of type 'Props | undefined' is not assignable to parameter of type 'Props'. Type 'undefined' is not assignable to type 'Props'.

これはから来ているコードは、このです:

これを引き起こしているのかわから
export class ScratchpadComponent extends React.Component<ScratchpadComponent.Props, ScratchpadComponent.State> { 

    constructor(props?: ScratchpadComponent.Props, context?: any) { 
     super(props, context); 
     this.submit = this.submit.bind(this); 
    } 

ない - 私は周りに検索しませんしましたこれを解決する方法には多くの手がかりがありますか?

更新:

オプションの?

18,11): error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<Pick<Props, "dispatch" | "scratchPadActi...'. 
    Type '{}' is not assignable to type 'Readonly<Pick<Props, "dispatch" | "scratchPadActions" | "scratchData" | "errorMessage" | "errorDa...'. 
    Property 'dispatch' is missing in type '{}'. 

答えて

1

スーパークラスのコンストラクタは、最初の引数としてPropsを想定しています。あなたがそう

constructor(props: ScratchpadComponent.Props, context?: any) 

として

constructor(props?: ScratchpadComponent.Props, context?: any) 

ないとして、それを宣言したため、呼び出し側が任意の引数を渡さない場合は、サブクラスのコンストラクタは、小道具、、、引数なしで呼び出すことができ未定義であり、 undefinedをスーパーコンストラクタに渡そうとしていますが、undefinedは受け付けません。

+0

ちょっと私はコンポーネント定義からオプションの署名を削除して、今見ているエラーで質問を更新しました。あなたはこのエラーを取り除く方法を知っていますか? –