00d4b4cb50
Fixes bug #4404
83 lines
1.8 KiB
Plaintext
83 lines
1.8 KiB
Plaintext
=== tests/cases/conformance/jsx/tsxTypeErrors.tsx ===
|
|
|
|
// A built-in element (OK)
|
|
var a1 = <div id="foo" />;
|
|
>a1 : any
|
|
><div id="foo" /> : any
|
|
>div : any
|
|
>id : any
|
|
|
|
// A built-in element with a mistyped property (error)
|
|
var a2 = <img srce="foo.jpg" />
|
|
>a2 : any
|
|
><img srce="foo.jpg" /> : any
|
|
>img : any
|
|
>srce : any
|
|
|
|
// A built-in element with a badly-typed attribute value (error)
|
|
var thing = { oops: 100 };
|
|
>thing : { oops: number; }
|
|
>{ oops: 100 } : { oops: number; }
|
|
>oops : number
|
|
>100 : number
|
|
|
|
var a3 = <div id={thing} />
|
|
>a3 : any
|
|
><div id={thing} /> : any
|
|
>div : any
|
|
>id : any
|
|
>thing : { oops: number; }
|
|
|
|
// Mistyped html name (error)
|
|
var e1 = <imag src="bar.jpg" />
|
|
>e1 : any
|
|
><imag src="bar.jpg" /> : any
|
|
>imag : any
|
|
>src : any
|
|
|
|
// A custom type
|
|
class MyClass {
|
|
>MyClass : MyClass
|
|
|
|
props: {
|
|
>props : { pt?: { x: number; y: number; }; name?: string; reqd: boolean; }
|
|
|
|
pt?: { x: number; y: number; };
|
|
>pt : { x: number; y: number; }
|
|
>x : number
|
|
>y : number
|
|
|
|
name?: string;
|
|
>name : string
|
|
|
|
reqd: boolean;
|
|
>reqd : boolean
|
|
}
|
|
}
|
|
|
|
// Let's use it
|
|
// TODO: Error on missing 'reqd'
|
|
var b1 = <MyClass reqd={true} />;
|
|
>b1 : any
|
|
><MyClass reqd={true} /> : any
|
|
>MyClass : typeof MyClass
|
|
>reqd : any
|
|
>true : boolean
|
|
|
|
// 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'}} />;
|
|
>b2 : any
|
|
><MyClass pt={{x: 4, y: 'oops'}} /> : any
|
|
>MyClass : typeof MyClass
|
|
>pt : any
|
|
>{x: 4, y: 'oops'} : { x: number; y: string; }
|
|
>x : number
|
|
>4 : number
|
|
>y : string
|
|
>'oops' : string
|
|
|
|
|