forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
312 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
tests/cases/conformance/jsx/file.tsx(8,15): error TS2339: Property 'srce' does not exist on type 'HTMLProps<HTMLImageElement>'. | ||
tests/cases/conformance/jsx/file.tsx(12,15): error TS2322: Type '{ oops: number; }' is not assignable to type 'string'. | ||
tests/cases/conformance/jsx/file.tsx(15,10): error TS2339: Property 'imag' does not exist on type 'JSX.IntrinsicElements'. | ||
tests/cases/conformance/jsx/file.tsx(32,10): error TS2324: Property 'reqd' is missing in type 'IntrinsicAttributes & IntrinsicClassAttributes<MyClass> & { pt?: { x: number; y: number; }; name?: string; reqd: boolean; }'. | ||
tests/cases/conformance/jsx/file.tsx(32,19): error TS2322: Type '{ x: number; y: string; }' is not assignable to type '{ x: number; y: number; }'. | ||
Types of property 'y' are incompatible. | ||
Type 'string' is not assignable to type 'number'. | ||
tests/cases/conformance/jsx/file.tsx(44,25): error TS2322: Type 'HTMLProps<HTMLDivElement>' is not assignable to type 'MyClass'. | ||
Property 'setState' is missing in type 'HTMLProps<HTMLDivElement>'. | ||
tests/cases/conformance/jsx/file.tsx(44,32): error TS2322: Type 'HTMLProps<HTMLDivElement>' is not assignable to type 'MyClass'. | ||
|
||
|
||
==== tests/cases/conformance/jsx/file.tsx (7 errors) ==== | ||
|
||
import React = require('react'); | ||
|
||
// A built-in element (OK) | ||
var a1 = <div id="foo" />; | ||
|
||
// A built-in element with a mistyped property (error) | ||
var a2 = <img srce="foo.jpg" /> | ||
~~~~ | ||
!!! error TS2339: Property 'srce' does not exist on type 'HTMLProps<HTMLImageElement>'. | ||
|
||
// A built-in element with a badly-typed attribute value (error) | ||
var thing = { oops: 100 }; | ||
var a3 = <div id={thing} /> | ||
~~~~~~~~~~ | ||
!!! error TS2322: Type '{ oops: number; }' is not assignable to type 'string'. | ||
|
||
// Mistyped html name (error) | ||
var e1 = <imag src="bar.jpg" /> | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2339: Property 'imag' does not exist on type 'JSX.IntrinsicElements'. | ||
|
||
class MyClass extends React.Component<{ | ||
pt?: { x: number; y: number; }; | ||
name?: string; | ||
reqd: boolean; | ||
}, any> { | ||
} | ||
|
||
// Let's use it | ||
// TODO: Error on missing 'reqd' | ||
var b1 = <MyClass reqd={true} />; | ||
|
||
// Mistyped attribute member | ||
// sample.tsx(23,22): error TS2322: Type '{ x: number; y: string; }' is not assignable to type '{ x: number; y: number; }'. | ||
// Types of property 'y' are incompatible. | ||
// Type 'string' is not assignable to type 'number'. | ||
var b2 = <MyClass pt={{x: 4, y: 'oops'}} />; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2324: Property 'reqd' is missing in type 'IntrinsicAttributes & IntrinsicClassAttributes<MyClass> & { pt?: { x: number; y: number; }; name?: string; reqd: boolean; }'. | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2322: Type '{ x: number; y: string; }' is not assignable to type '{ x: number; y: number; }'. | ||
!!! error TS2322: Types of property 'y' are incompatible. | ||
!!! error TS2322: Type 'string' is not assignable to type 'number'. | ||
|
||
// A custom element type with an explicit children prop attribute type | ||
|
||
class MyParentClass extends React.Component<{ | ||
children?: MyClass[]; | ||
}, any> { | ||
} | ||
|
||
// OK - Child element matches the children prop | ||
var d1 = <MyParentClass><MyClass reqd={true} /><MyClass reqd={true}></MyClass></MyParentClass> | ||
// Error - Incorrect child element type | ||
var d2 = <MyParentClass><div /><div></div><MyClass reqd={true} /><MyClass reqd={true}></MyClass></MyParentClass> | ||
~~~~~~~ | ||
!!! error TS2322: Type 'HTMLProps<HTMLDivElement>' is not assignable to type 'MyClass'. | ||
!!! error TS2322: Property 'setState' is missing in type 'HTMLProps<HTMLDivElement>'. | ||
~~~~~ | ||
!!! error TS2322: Type 'HTMLProps<HTMLDivElement>' is not assignable to type 'MyClass'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.