TypeScript/tests/cases/conformance/jsx/tsxAttributeResolution5.tsx

33 lines
657 B
TypeScript
Raw Normal View History

2015-06-18 23:03:43 +02:00
//@filename: file.tsx
//@jsx: preserve
declare module JSX {
interface Element { }
interface IntrinsicElements {
test1: Attribs1;
test2: Attribs2;
}
}
interface Attribs1 {
x: string;
}
interface Attribs2 {
toString(): string;
}
function make1<T extends {x: string}> (obj: T) {
return <test1 {...obj} />; // OK
}
function make2<T extends {x: number}> (obj: T) {
return <test1 {...obj} />; // Error (x is number, not string)
}
function make3<T extends {y: string}> (obj: T) {
return <test1 {...obj} />; // Error, missing x
}
<test1 {...{}} />; // Error, missing x
<test2 {...{}} />; // Error, missing toString