Ich habe von Version 1.6 auf Typoskript auf Version 2.1.6 aktualisiert und die Typisierung für die Reaktion auf Version 15.0.15. Wenn ich die Typoskript-Dateien über gulp oder TSC kompiliere, funktioniert alles gut und es gibt keine Fehlermeldungen. Visual Studio 2017 RC sowie Sublime Text beschweren sich jedoch über den Typoskript-Code.JSX-Elementtyp 'CounterDisplay' ist keine Konstruktorfunktion für JSX-Elemente. Die Typen der Eigenschaft 'refs' sind inkompatibel
Hier ist ein Teil meines Codes. Dies erzeugt keine Fehler.
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>
)}
}
Die Render-Funktion einer anderen Komponente enthält:
<CounterDisplay
loading={props.counterIsLoading}
first={props.skip + 1}
last={props.skip + props.take}
total={props.counter} />
Der obige Code der den Fehler erzeugt, die sowohl in Visual Studio 2017 sowie Erhabene Text 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.
Visuelle Studio und Sublime Text beschweren sich, wenn ich eine reaktive Komponente verwende, die ich selbst geschrieben habe. Ich frage mich, warum dieser Code funktioniert, wenn Sie den Compiler verwenden, aber nicht, wenn Sie die IDE verwenden. Kannst du mir helfen?
Wie sollen wir Ihnen helfen, wenn Sie die Definition für 'Zoom' nicht angegeben haben? –
Entschuldigung, mein Fehler. Ich habe das ein bisschen gemischt. Es ist jedoch nicht wirklich wichtig, denn ich bekomme den gleichen Fehler mit jeder React-Komponente, die ich habe. – Alex
Der Fehler weist darauf hin, dass Sie zwei Kopien von "react" importiert haben - eine vollständige Repro wird benötigt. –