2017-06-02 7 views
0

最小限の例を反応させるために小道具を供給する場合:活字体および/ JSXを反応させる:TSCコンパイラエラーを再現するために、コンポーネントのスーパー

const React = require("react"); 

class ExampleForm extends React.Component { 
    constructor(props) { 
     super(props); 
    } 

    render() { 
     return <p>{ this.props.msg }</p>; 
    } 
}; 

コンパイラコマンド:

tsc --jsx react react_components/example.tsx 

エラー:

react_components/example.tsx(5,9): error TS2346: Supplied parameters do not match any signature of call target.

これはバグですか? tscコマンドラインフラグ/オプションがありませんか?

EDIT:

インストールの種類:

  • "タイプが/反応@": "タイプ/ノード@" "^ 15.0.25"
  • : "^ 7.0.23"

TSCのバージョンは2.3.4

+0

これは役に立ちます。 https://charleslbryant.gitbooks.io/hello-react-and-typescript/Samples/ComponentPropsAndState.html – SLee

+0

@SLeeこれは多くの役に立ちます。あなたはクレジットを得るために答えとして言い換えることができますか?基本的に 'React.Component'の後にを追加し、' 'のデフォルト値を' 'とし、必要に応じてpropsのインターフェースを指定する必要があります。 – BlackSheep

+0

それは多くの助けを聞いてうれしい。私はニックの答えも同じことをカバーしていると思います。あなたは彼に信用を与えることができます:) Upvoteのコメントは私のために十分です – SLee

答えて

2

代わりにリアクトためES6のインポートを使用してみてください、とも小道具のためにあなたのインターフェースをdelcareすることを確認していますs。

import * as React from 'react'; 

interface IProps { 
    msg: string; 
} 

export class ExampleForm extends React.Component<IProps, {}> { 
    constructor(props: IProps) { 
    super(props); 
    } 

    render() { 
    return <p>{this.props.msg}</p>; 
    } 
} 
関連する問題