バージョン2.1.6のtypescriptをバージョン1.6から、そして入力をバージョン15.0.15に更新しました。 gulpやtscでtypescriptファイルをコンパイルすると、すべて正常に動作し、エラーメッセージは表示されません。しかし、Visual Studio 2017 RCとSublime Textは、typescriptコードについて不平を言っています。JSX要素タイプ 'CounterDisplay'はJSX要素のコンストラクタ関数ではありません。プロパティの型 'refs'は互換性がありません
ここに私のコードがあります。これによりエラーは発生しません。
interface CounterDisplayProps {
loading: boolean;
first: number;
last: number;
total: number;
}
class CounterDisplay extends React.Component<CounterDisplayProps, {}> {
render() {
var { props } = this;
return (
<div className="Counter">
Showing {props.first} to {props.total ? Math.min(props.last, props.total) : props.last} of {props.loading ? "?" : props.total} entries
</div>
)}
}
別のコンポーネントのレンダリング機能が含ま:
<CounterDisplay
loading={props.counterIsLoading}
first={props.skip + 1}
last={props.skip + props.take}
total={props.counter} />
上記の両方のVisual Studio 2017年にfollwowsエラーを生成しているコードだけでなく、崇高本文:
JSX element type 'CounterDisplay' is not a constructor function for JSX elements.
Types of property 'refs' are incompatible.
Type '{ [key: string]: ReactInstance; }' is not assignable to type '{
[key: string]: Component<any, any>; }'.
Index signatures are incompatible.
Type 'ReactInstance' is not assignable to type 'Component<any, any>'.
Type 'React.Component<any, any>' is not assignable to type 'React.Component<any, any>'. Two different types with this name exist, but they are unrelated.
Types of property 'refs' are incompatible.
Type '{ [key: string]: ReactInstance; }' is not assignable to type '{
[key: string]: Component<any, any>; }'.
Index signatures are incompatible.
Type 'ReactInstance' is not assignable to type 'Component<any, any>'.
Type 'React.Component<any, any>' is not assignable to type 'React.Component<any, any>'. Two different types with this name exist, but they are unrelated.
ビジュアルスタジオと崇高なテキストは、私が自分で書いた反応コンポーネントを使うたびに不平を言っています。私はなぜこのコードがコンパイラを使用しているときにIDEを使用していないときに動作しているのだろうかと思っています。手伝って頂けますか?
「ズーム」の定義を提供していないときは、どのようにお手伝いしますか? –
申し訳ありませんが、私の間違いです。私は少しこれを混ぜた。しかし、私が持っている全ての反応成分で同じエラーが出るので、実際にはそれほど重要ではありません。 – Alex
エラーは何とか 'react'の2つのコピーをインポートしたことを意味します。完全な再書き込みが必要です –