70 lines
2.2 KiB
Text
70 lines
2.2 KiB
Text
=== tests/cases/conformance/jsx/tsxTypeErrors.tsx ===
|
|
|
|
// A built-in element (OK)
|
|
var a1 = <div id="foo" />;
|
|
>a1 : Symbol(a1, Decl(tsxTypeErrors.tsx, 2, 3))
|
|
>div : Symbol(unknown)
|
|
>id : Symbol(unknown)
|
|
|
|
// A built-in element with a mistyped property (error)
|
|
var a2 = <img srce="foo.jpg" />
|
|
>a2 : Symbol(a2, Decl(tsxTypeErrors.tsx, 5, 3))
|
|
>img : Symbol(unknown)
|
|
>srce : Symbol(unknown)
|
|
|
|
// A built-in element with a badly-typed attribute value (error)
|
|
var thing = { oops: 100 };
|
|
>thing : Symbol(thing, Decl(tsxTypeErrors.tsx, 8, 3))
|
|
>oops : Symbol(oops, Decl(tsxTypeErrors.tsx, 8, 13))
|
|
|
|
var a3 = <div id={thing} />
|
|
>a3 : Symbol(a3, Decl(tsxTypeErrors.tsx, 9, 3))
|
|
>div : Symbol(unknown)
|
|
>id : Symbol(unknown)
|
|
>thing : Symbol(thing, Decl(tsxTypeErrors.tsx, 8, 3))
|
|
|
|
// Mistyped html name (error)
|
|
var e1 = <imag src="bar.jpg" />
|
|
>e1 : Symbol(e1, Decl(tsxTypeErrors.tsx, 12, 3))
|
|
>imag : Symbol(unknown)
|
|
>src : Symbol(unknown)
|
|
|
|
// A custom type
|
|
class MyClass {
|
|
>MyClass : Symbol(MyClass, Decl(tsxTypeErrors.tsx, 12, 31))
|
|
|
|
props: {
|
|
>props : Symbol(MyClass.props, Decl(tsxTypeErrors.tsx, 15, 15))
|
|
|
|
pt?: { x: number; y: number; };
|
|
>pt : Symbol(pt, Decl(tsxTypeErrors.tsx, 16, 10))
|
|
>x : Symbol(x, Decl(tsxTypeErrors.tsx, 17, 10))
|
|
>y : Symbol(y, Decl(tsxTypeErrors.tsx, 17, 21))
|
|
|
|
name?: string;
|
|
>name : Symbol(name, Decl(tsxTypeErrors.tsx, 17, 35))
|
|
|
|
reqd: boolean;
|
|
>reqd : Symbol(reqd, Decl(tsxTypeErrors.tsx, 18, 15))
|
|
}
|
|
}
|
|
|
|
// Let's use it
|
|
// TODO: Error on missing 'reqd'
|
|
var b1 = <MyClass reqd={true} />;
|
|
>b1 : Symbol(b1, Decl(tsxTypeErrors.tsx, 25, 3))
|
|
>MyClass : Symbol(MyClass, Decl(tsxTypeErrors.tsx, 12, 31))
|
|
>reqd : Symbol(unknown)
|
|
|
|
// 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 : Symbol(b2, Decl(tsxTypeErrors.tsx, 31, 3))
|
|
>MyClass : Symbol(MyClass, Decl(tsxTypeErrors.tsx, 12, 31))
|
|
>pt : Symbol(unknown)
|
|
>x : Symbol(x, Decl(tsxTypeErrors.tsx, 31, 23))
|
|
>y : Symbol(y, Decl(tsxTypeErrors.tsx, 31, 28))
|
|
|
|
|