Add tests and update baselines

This commit is contained in:
Kanchalai Tanglertsampan 2017-01-23 11:52:31 -08:00
parent 0b4f25c3f5
commit 378f444e14
11 changed files with 274 additions and 308 deletions

View File

@ -1,59 +0,0 @@
tests/cases/conformance/jsx/file.tsx(16,25): error TS2698: Spread types may only be created from object types.
tests/cases/conformance/jsx/file.tsx(17,25): error TS2698: Spread types may only be created from object types.
tests/cases/conformance/jsx/file.tsx(25,33): error TS2698: Spread types may only be created from object types.
tests/cases/conformance/jsx/file.tsx(26,34): error TS2698: Spread types may only be created from object types.
tests/cases/conformance/jsx/file.tsx(27,33): error TS2698: Spread types may only be created from object types.
==== tests/cases/conformance/jsx/file.tsx (5 errors) ====
import React = require('react')
declare function ComponentWithTwoAttributes<K,V>(l: {key1: K, value: V}): JSX.Element;
// OK
function Baz<T,U>(key1: T, value: U) {
let a0 = <ComponentWithTwoAttributes key1={key1} value={value} />
let a1 = <ComponentWithTwoAttributes {...{key1, value: value}} key="Component" />
}
// OK
declare function Component<U>(l: U): JSX.Element;
function createComponent<T extends {prop: number}>(arg:T) {
let a1 = <Component {...arg} />;
~~~~~~~~
!!! error TS2698: Spread types may only be created from object types.
let a2 = <Component {...arg} prop1 />;
~~~~~~~~
!!! error TS2698: Spread types may only be created from object types.
}
declare function ComponentSpecific<U>(l: {prop: U}): JSX.Element;
declare function ComponentSpecific1<U>(l: {prop: U, "ignore-prop": number}): JSX.Element;
// OK
function Bar<T extends {prop: number}>(arg: T) {
let a1 = <ComponentSpecific {...arg} ignore-prop="hi" />; // U is number
~~~~~~~~
!!! error TS2698: Spread types may only be created from object types.
let a2 = <ComponentSpecific1 {...arg} ignore-prop={10} />; // U is number
~~~~~~~~
!!! error TS2698: Spread types may only be created from object types.
let a3 = <ComponentSpecific {...arg} prop="hello" />; // U is "hello"
~~~~~~~~
!!! error TS2698: Spread types may only be created from object types.
}
declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;
// OK
function createLink(func: (a: number)=>void) {
let o = <Link func={func} />
}
function createLink1(func: (a: number)=>boolean) {
let o = <Link func={func} />
}

View File

@ -2,7 +2,6 @@
import React = require('react')
declare function ComponentWithTwoAttributes<K,V>(l: {key1: K, value: V}): JSX.Element;
// OK
@ -11,23 +10,6 @@ function Baz<T,U>(key1: T, value: U) {
let a1 = <ComponentWithTwoAttributes {...{key1, value: value}} key="Component" />
}
// OK
declare function Component<U>(l: U): JSX.Element;
function createComponent<T extends {prop: number}>(arg:T) {
let a1 = <Component {...arg} />;
let a2 = <Component {...arg} prop1 />;
}
declare function ComponentSpecific<U>(l: {prop: U}): JSX.Element;
declare function ComponentSpecific1<U>(l: {prop: U, "ignore-prop": number}): JSX.Element;
// OK
function Bar<T extends {prop: number}>(arg: T) {
let a1 = <ComponentSpecific {...arg} ignore-prop="hi" />; // U is number
let a2 = <ComponentSpecific1 {...arg} ignore-prop={10} />; // U is number
let a3 = <ComponentSpecific {...arg} prop="hello" />; // U is "hello"
}
declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;
// OK
@ -39,7 +21,15 @@ function createLink1(func: (a: number)=>boolean) {
let o = <Link func={func} />
}
interface InferParamProp<T> {
values: Array<T>;
selectHandler: (selectedVal: T) => void;
}
declare function InferParamComponent<T>(attr: InferParamProp<T>): JSX.Element;
// OK
let i = <InferParamComponent values={[1, 2, 3, 4]} selectHandler={(val) => { }} />;
//// [file.jsx]
define(["require", "exports", "react"], function (require, exports, React) {
@ -49,16 +39,6 @@ define(["require", "exports", "react"], function (require, exports, React) {
var a0 = <ComponentWithTwoAttributes key1={key1} value={value}/>;
var a1 = <ComponentWithTwoAttributes {...{ key1: key1, value: value }} key="Component"/>;
}
function createComponent(arg) {
var a1 = <Component {...arg}/>;
var a2 = <Component {...arg} prop1/>;
}
// OK
function Bar(arg) {
var a1 = <ComponentSpecific {...arg} ignore-prop="hi"/>; // U is number
var a2 = <ComponentSpecific1 {...arg} ignore-prop={10}/>; // U is number
var a3 = <ComponentSpecific {...arg} prop="hello"/>; // U is "hello"
}
// OK
function createLink(func) {
var o = <Link func={func}/>;
@ -66,4 +46,6 @@ define(["require", "exports", "react"], function (require, exports, React) {
function createLink1(func) {
var o = <Link func={func}/>;
}
// OK
var i = <InferParamComponent values={[1, 2, 3, 4]} selectHandler={function (val) { }}/>;
});

View File

@ -3,152 +3,109 @@
import React = require('react')
>React : Symbol(React, Decl(file.tsx, 0, 0))
declare function ComponentWithTwoAttributes<K,V>(l: {key1: K, value: V}): JSX.Element;
>ComponentWithTwoAttributes : Symbol(ComponentWithTwoAttributes, Decl(file.tsx, 1, 31))
>K : Symbol(K, Decl(file.tsx, 4, 44))
>V : Symbol(V, Decl(file.tsx, 4, 46))
>l : Symbol(l, Decl(file.tsx, 4, 49))
>key1 : Symbol(key1, Decl(file.tsx, 4, 53))
>K : Symbol(K, Decl(file.tsx, 4, 44))
>value : Symbol(value, Decl(file.tsx, 4, 61))
>V : Symbol(V, Decl(file.tsx, 4, 46))
>K : Symbol(K, Decl(file.tsx, 3, 44))
>V : Symbol(V, Decl(file.tsx, 3, 46))
>l : Symbol(l, Decl(file.tsx, 3, 49))
>key1 : Symbol(key1, Decl(file.tsx, 3, 53))
>K : Symbol(K, Decl(file.tsx, 3, 44))
>value : Symbol(value, Decl(file.tsx, 3, 61))
>V : Symbol(V, Decl(file.tsx, 3, 46))
>JSX : Symbol(JSX, Decl(react.d.ts, 2352, 1))
>Element : Symbol(JSX.Element, Decl(react.d.ts, 2355, 27))
// OK
function Baz<T,U>(key1: T, value: U) {
>Baz : Symbol(Baz, Decl(file.tsx, 4, 86))
>T : Symbol(T, Decl(file.tsx, 7, 13))
>U : Symbol(U, Decl(file.tsx, 7, 15))
>key1 : Symbol(key1, Decl(file.tsx, 7, 18))
>T : Symbol(T, Decl(file.tsx, 7, 13))
>value : Symbol(value, Decl(file.tsx, 7, 26))
>U : Symbol(U, Decl(file.tsx, 7, 15))
>Baz : Symbol(Baz, Decl(file.tsx, 3, 86))
>T : Symbol(T, Decl(file.tsx, 6, 13))
>U : Symbol(U, Decl(file.tsx, 6, 15))
>key1 : Symbol(key1, Decl(file.tsx, 6, 18))
>T : Symbol(T, Decl(file.tsx, 6, 13))
>value : Symbol(value, Decl(file.tsx, 6, 26))
>U : Symbol(U, Decl(file.tsx, 6, 15))
let a0 = <ComponentWithTwoAttributes key1={key1} value={value} />
>a0 : Symbol(a0, Decl(file.tsx, 8, 7))
>a0 : Symbol(a0, Decl(file.tsx, 7, 7))
>ComponentWithTwoAttributes : Symbol(ComponentWithTwoAttributes, Decl(file.tsx, 1, 31))
>key1 : Symbol(key1, Decl(file.tsx, 8, 40))
>key1 : Symbol(key1, Decl(file.tsx, 7, 18))
>value : Symbol(value, Decl(file.tsx, 8, 52))
>value : Symbol(value, Decl(file.tsx, 7, 26))
>key1 : Symbol(key1, Decl(file.tsx, 7, 40))
>key1 : Symbol(key1, Decl(file.tsx, 6, 18))
>value : Symbol(value, Decl(file.tsx, 7, 52))
>value : Symbol(value, Decl(file.tsx, 6, 26))
let a1 = <ComponentWithTwoAttributes {...{key1, value: value}} key="Component" />
>a1 : Symbol(a1, Decl(file.tsx, 9, 7))
>a1 : Symbol(a1, Decl(file.tsx, 8, 7))
>ComponentWithTwoAttributes : Symbol(ComponentWithTwoAttributes, Decl(file.tsx, 1, 31))
>key1 : Symbol(key1, Decl(file.tsx, 9, 46))
>value : Symbol(value, Decl(file.tsx, 9, 51))
>value : Symbol(value, Decl(file.tsx, 7, 26))
>key : Symbol(key, Decl(file.tsx, 9, 66))
}
// OK
declare function Component<U>(l: U): JSX.Element;
>Component : Symbol(Component, Decl(file.tsx, 10, 1))
>U : Symbol(U, Decl(file.tsx, 13, 27))
>l : Symbol(l, Decl(file.tsx, 13, 30))
>U : Symbol(U, Decl(file.tsx, 13, 27))
>JSX : Symbol(JSX, Decl(react.d.ts, 2352, 1))
>Element : Symbol(JSX.Element, Decl(react.d.ts, 2355, 27))
function createComponent<T extends {prop: number}>(arg:T) {
>createComponent : Symbol(createComponent, Decl(file.tsx, 13, 49))
>T : Symbol(T, Decl(file.tsx, 14, 25))
>prop : Symbol(prop, Decl(file.tsx, 14, 36))
>arg : Symbol(arg, Decl(file.tsx, 14, 51))
>T : Symbol(T, Decl(file.tsx, 14, 25))
let a1 = <Component {...arg} />;
>a1 : Symbol(a1, Decl(file.tsx, 15, 7))
>Component : Symbol(Component, Decl(file.tsx, 10, 1))
>arg : Symbol(arg, Decl(file.tsx, 14, 51))
let a2 = <Component {...arg} prop1 />;
>a2 : Symbol(a2, Decl(file.tsx, 16, 7))
>Component : Symbol(Component, Decl(file.tsx, 10, 1))
>arg : Symbol(arg, Decl(file.tsx, 14, 51))
>prop1 : Symbol(prop1, Decl(file.tsx, 16, 32))
}
declare function ComponentSpecific<U>(l: {prop: U}): JSX.Element;
>ComponentSpecific : Symbol(ComponentSpecific, Decl(file.tsx, 17, 1))
>U : Symbol(U, Decl(file.tsx, 19, 35))
>l : Symbol(l, Decl(file.tsx, 19, 38))
>prop : Symbol(prop, Decl(file.tsx, 19, 42))
>U : Symbol(U, Decl(file.tsx, 19, 35))
>JSX : Symbol(JSX, Decl(react.d.ts, 2352, 1))
>Element : Symbol(JSX.Element, Decl(react.d.ts, 2355, 27))
declare function ComponentSpecific1<U>(l: {prop: U, "ignore-prop": number}): JSX.Element;
>ComponentSpecific1 : Symbol(ComponentSpecific1, Decl(file.tsx, 19, 65))
>U : Symbol(U, Decl(file.tsx, 20, 36))
>l : Symbol(l, Decl(file.tsx, 20, 39))
>prop : Symbol(prop, Decl(file.tsx, 20, 43))
>U : Symbol(U, Decl(file.tsx, 20, 36))
>JSX : Symbol(JSX, Decl(react.d.ts, 2352, 1))
>Element : Symbol(JSX.Element, Decl(react.d.ts, 2355, 27))
// OK
function Bar<T extends {prop: number}>(arg: T) {
>Bar : Symbol(Bar, Decl(file.tsx, 20, 89))
>T : Symbol(T, Decl(file.tsx, 23, 13))
>prop : Symbol(prop, Decl(file.tsx, 23, 24))
>arg : Symbol(arg, Decl(file.tsx, 23, 39))
>T : Symbol(T, Decl(file.tsx, 23, 13))
let a1 = <ComponentSpecific {...arg} ignore-prop="hi" />; // U is number
>a1 : Symbol(a1, Decl(file.tsx, 24, 7))
>ComponentSpecific : Symbol(ComponentSpecific, Decl(file.tsx, 17, 1))
>arg : Symbol(arg, Decl(file.tsx, 23, 39))
>ignore-prop : Symbol(ignore-prop, Decl(file.tsx, 24, 40))
let a2 = <ComponentSpecific1 {...arg} ignore-prop={10} />; // U is number
>a2 : Symbol(a2, Decl(file.tsx, 25, 7))
>ComponentSpecific1 : Symbol(ComponentSpecific1, Decl(file.tsx, 19, 65))
>arg : Symbol(arg, Decl(file.tsx, 23, 39))
>ignore-prop : Symbol(ignore-prop, Decl(file.tsx, 25, 41))
let a3 = <ComponentSpecific {...arg} prop="hello" />; // U is "hello"
>a3 : Symbol(a3, Decl(file.tsx, 26, 7))
>ComponentSpecific : Symbol(ComponentSpecific, Decl(file.tsx, 17, 1))
>arg : Symbol(arg, Decl(file.tsx, 23, 39))
>prop : Symbol(prop, Decl(file.tsx, 26, 40))
>key1 : Symbol(key1, Decl(file.tsx, 8, 46))
>value : Symbol(value, Decl(file.tsx, 8, 51))
>value : Symbol(value, Decl(file.tsx, 6, 26))
>key : Symbol(key, Decl(file.tsx, 8, 66))
}
declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;
>Link : Symbol(Link, Decl(file.tsx, 27, 1))
>U : Symbol(U, Decl(file.tsx, 29, 22))
>l : Symbol(l, Decl(file.tsx, 29, 25))
>func : Symbol(func, Decl(file.tsx, 29, 29))
>arg : Symbol(arg, Decl(file.tsx, 29, 36))
>U : Symbol(U, Decl(file.tsx, 29, 22))
>Link : Symbol(Link, Decl(file.tsx, 9, 1))
>U : Symbol(U, Decl(file.tsx, 11, 22))
>l : Symbol(l, Decl(file.tsx, 11, 25))
>func : Symbol(func, Decl(file.tsx, 11, 29))
>arg : Symbol(arg, Decl(file.tsx, 11, 36))
>U : Symbol(U, Decl(file.tsx, 11, 22))
>JSX : Symbol(JSX, Decl(react.d.ts, 2352, 1))
>Element : Symbol(JSX.Element, Decl(react.d.ts, 2355, 27))
// OK
function createLink(func: (a: number)=>void) {
>createLink : Symbol(createLink, Decl(file.tsx, 29, 65))
>func : Symbol(func, Decl(file.tsx, 32, 20))
>a : Symbol(a, Decl(file.tsx, 32, 27))
>createLink : Symbol(createLink, Decl(file.tsx, 11, 65))
>func : Symbol(func, Decl(file.tsx, 14, 20))
>a : Symbol(a, Decl(file.tsx, 14, 27))
let o = <Link func={func} />
>o : Symbol(o, Decl(file.tsx, 33, 7))
>Link : Symbol(Link, Decl(file.tsx, 27, 1))
>func : Symbol(func, Decl(file.tsx, 33, 17))
>func : Symbol(func, Decl(file.tsx, 32, 20))
>o : Symbol(o, Decl(file.tsx, 15, 7))
>Link : Symbol(Link, Decl(file.tsx, 9, 1))
>func : Symbol(func, Decl(file.tsx, 15, 17))
>func : Symbol(func, Decl(file.tsx, 14, 20))
}
function createLink1(func: (a: number)=>boolean) {
>createLink1 : Symbol(createLink1, Decl(file.tsx, 34, 1))
>func : Symbol(func, Decl(file.tsx, 36, 21))
>a : Symbol(a, Decl(file.tsx, 36, 28))
>createLink1 : Symbol(createLink1, Decl(file.tsx, 16, 1))
>func : Symbol(func, Decl(file.tsx, 18, 21))
>a : Symbol(a, Decl(file.tsx, 18, 28))
let o = <Link func={func} />
>o : Symbol(o, Decl(file.tsx, 37, 7))
>Link : Symbol(Link, Decl(file.tsx, 27, 1))
>func : Symbol(func, Decl(file.tsx, 37, 17))
>func : Symbol(func, Decl(file.tsx, 36, 21))
>o : Symbol(o, Decl(file.tsx, 19, 7))
>Link : Symbol(Link, Decl(file.tsx, 9, 1))
>func : Symbol(func, Decl(file.tsx, 19, 17))
>func : Symbol(func, Decl(file.tsx, 18, 21))
}
interface InferParamProp<T> {
>InferParamProp : Symbol(InferParamProp, Decl(file.tsx, 20, 1))
>T : Symbol(T, Decl(file.tsx, 22, 25))
values: Array<T>;
>values : Symbol(InferParamProp.values, Decl(file.tsx, 22, 29))
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>T : Symbol(T, Decl(file.tsx, 22, 25))
selectHandler: (selectedVal: T) => void;
>selectHandler : Symbol(InferParamProp.selectHandler, Decl(file.tsx, 23, 21))
>selectedVal : Symbol(selectedVal, Decl(file.tsx, 24, 20))
>T : Symbol(T, Decl(file.tsx, 22, 25))
}
declare function InferParamComponent<T>(attr: InferParamProp<T>): JSX.Element;
>InferParamComponent : Symbol(InferParamComponent, Decl(file.tsx, 25, 1))
>T : Symbol(T, Decl(file.tsx, 27, 37))
>attr : Symbol(attr, Decl(file.tsx, 27, 40))
>InferParamProp : Symbol(InferParamProp, Decl(file.tsx, 20, 1))
>T : Symbol(T, Decl(file.tsx, 27, 37))
>JSX : Symbol(JSX, Decl(react.d.ts, 2352, 1))
>Element : Symbol(JSX.Element, Decl(react.d.ts, 2355, 27))
// OK
let i = <InferParamComponent values={[1, 2, 3, 4]} selectHandler={(val) => { }} />;
>i : Symbol(i, Decl(file.tsx, 30, 3))
>InferParamComponent : Symbol(InferParamComponent, Decl(file.tsx, 25, 1))
>values : Symbol(values, Decl(file.tsx, 30, 28))
>selectHandler : Symbol(selectHandler, Decl(file.tsx, 30, 50))
>val : Symbol(val, Decl(file.tsx, 30, 67))

View File

@ -3,7 +3,6 @@
import React = require('react')
>React : typeof React
declare function ComponentWithTwoAttributes<K,V>(l: {key1: K, value: V}): JSX.Element;
>ComponentWithTwoAttributes : <K, V>(l: { key1: K; value: V; }) => JSX.Element
>K : K
@ -46,85 +45,6 @@ function Baz<T,U>(key1: T, value: U) {
>key : string
}
// OK
declare function Component<U>(l: U): JSX.Element;
>Component : <U>(l: U) => JSX.Element
>U : U
>l : U
>U : U
>JSX : any
>Element : JSX.Element
function createComponent<T extends {prop: number}>(arg:T) {
>createComponent : <T extends { prop: number; }>(arg: T) => void
>T : T
>prop : number
>arg : T
>T : T
let a1 = <Component {...arg} />;
>a1 : JSX.Element
><Component {...arg} /> : JSX.Element
>Component : <U>(l: U) => JSX.Element
>arg : T
let a2 = <Component {...arg} prop1 />;
>a2 : JSX.Element
><Component {...arg} prop1 /> : JSX.Element
>Component : <U>(l: U) => JSX.Element
>arg : T
>prop1 : true
}
declare function ComponentSpecific<U>(l: {prop: U}): JSX.Element;
>ComponentSpecific : <U>(l: { prop: U; }) => JSX.Element
>U : U
>l : { prop: U; }
>prop : U
>U : U
>JSX : any
>Element : JSX.Element
declare function ComponentSpecific1<U>(l: {prop: U, "ignore-prop": number}): JSX.Element;
>ComponentSpecific1 : <U>(l: { prop: U; "ignore-prop": number; }) => JSX.Element
>U : U
>l : { prop: U; "ignore-prop": number; }
>prop : U
>U : U
>JSX : any
>Element : JSX.Element
// OK
function Bar<T extends {prop: number}>(arg: T) {
>Bar : <T extends { prop: number; }>(arg: T) => void
>T : T
>prop : number
>arg : T
>T : T
let a1 = <ComponentSpecific {...arg} ignore-prop="hi" />; // U is number
>a1 : JSX.Element
><ComponentSpecific {...arg} ignore-prop="hi" /> : JSX.Element
>ComponentSpecific : <U>(l: { prop: U; }) => JSX.Element
>arg : T
>ignore-prop : string
let a2 = <ComponentSpecific1 {...arg} ignore-prop={10} />; // U is number
>a2 : JSX.Element
><ComponentSpecific1 {...arg} ignore-prop={10} /> : JSX.Element
>ComponentSpecific1 : <U>(l: { prop: U; "ignore-prop": number; }) => JSX.Element
>arg : T
>ignore-prop : number
>10 : 10
let a3 = <ComponentSpecific {...arg} prop="hello" />; // U is "hello"
>a3 : JSX.Element
><ComponentSpecific {...arg} prop="hello" /> : JSX.Element
>ComponentSpecific : <U>(l: { prop: U; }) => JSX.Element
>arg : T
>prop : string
}
declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;
>Link : <U>(l: { func: (arg: U) => void; }) => JSX.Element
>U : U
@ -162,4 +82,42 @@ function createLink1(func: (a: number)=>boolean) {
>func : (a: number) => boolean
}
interface InferParamProp<T> {
>InferParamProp : InferParamProp<T>
>T : T
values: Array<T>;
>values : T[]
>Array : T[]
>T : T
selectHandler: (selectedVal: T) => void;
>selectHandler : (selectedVal: T) => void
>selectedVal : T
>T : T
}
declare function InferParamComponent<T>(attr: InferParamProp<T>): JSX.Element;
>InferParamComponent : <T>(attr: InferParamProp<T>) => JSX.Element
>T : T
>attr : InferParamProp<T>
>InferParamProp : InferParamProp<T>
>T : T
>JSX : any
>Element : JSX.Element
// OK
let i = <InferParamComponent values={[1, 2, 3, 4]} selectHandler={(val) => { }} />;
>i : JSX.Element
><InferParamComponent values={[1, 2, 3, 4]} selectHandler={(val) => { }} /> : JSX.Element
>InferParamComponent : <T>(attr: InferParamProp<T>) => JSX.Element
>values : number[]
>[1, 2, 3, 4] : number[]
>1 : 1
>2 : 2
>3 : 3
>4 : 4
>selectHandler : (val: number) => void
>(val) => { } : (val: number) => void
>val : number

View File

@ -4,9 +4,11 @@ tests/cases/conformance/jsx/file.tsx(21,19): error TS2322: Type '{ func: (a: num
Type '{ func: (a: number, b: string) => void; }' is not assignable to type '{ func: (arg: number) => void; }'.
Types of property 'func' are incompatible.
Type '(a: number, b: string) => void' is not assignable to type '(arg: number) => void'.
tests/cases/conformance/jsx/file.tsx(32,10): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'.
==== tests/cases/conformance/jsx/file.tsx (3 errors) ====
==== tests/cases/conformance/jsx/file.tsx (4 errors) ====
import React = require('react')
@ -37,4 +39,18 @@ tests/cases/conformance/jsx/file.tsx(21,19): error TS2322: Type '{ func: (a: num
!!! error TS2322: Type '{ func: (a: number, b: string) => void; }' is not assignable to type '{ func: (arg: number) => void; }'.
!!! error TS2322: Types of property 'func' are incompatible.
!!! error TS2322: Type '(a: number, b: string) => void' is not assignable to type '(arg: number) => void'.
}
}
interface InferParamProp<T> {
values: Array<T>;
selectHandler: (selectedVal: T) => void;
}
declare function InferParamComponent<T>(attr: InferParamProp<T>): JSX.Element;
// Error
let i = <InferParamComponent values={[1, 2, 3, 4]} selectHandler={(val: string) => { }} />;
~~~~~~~~~~~~~~~~~~~
!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
!!! error TS2453: Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'.

View File

@ -20,7 +20,18 @@ declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;
// Error
function createLink(func: (a: number, b: string)=>void) {
let o = <Link func={func} />
}
}
interface InferParamProp<T> {
values: Array<T>;
selectHandler: (selectedVal: T) => void;
}
declare function InferParamComponent<T>(attr: InferParamProp<T>): JSX.Element;
// Error
let i = <InferParamComponent values={[1, 2, 3, 4]} selectHandler={(val: string) => { }} />;
//// [file.jsx]
define(["require", "exports", "react"], function (require, exports, React) {
@ -37,4 +48,6 @@ define(["require", "exports", "react"], function (require, exports, React) {
function createLink(func) {
var o = <Link func={func}/>;
}
// Error
var i = <InferParamComponent values={[1, 2, 3, 4]} selectHandler={function (val) { }}/>;
});

View File

@ -0,0 +1,38 @@
tests/cases/conformance/jsx/file.tsx(7,25): error TS2698: Spread types may only be created from object types.
tests/cases/conformance/jsx/file.tsx(8,25): error TS2698: Spread types may only be created from object types.
tests/cases/conformance/jsx/file.tsx(16,33): error TS2698: Spread types may only be created from object types.
tests/cases/conformance/jsx/file.tsx(17,34): error TS2698: Spread types may only be created from object types.
tests/cases/conformance/jsx/file.tsx(18,33): error TS2698: Spread types may only be created from object types.
==== tests/cases/conformance/jsx/file.tsx (5 errors) ====
import React = require('react')
// Error, can only spread object type
declare function Component<U>(l: U): JSX.Element;
function createComponent<T extends { prop: number }>(arg: T) {
let a1 = <Component {...arg} />;
~~~~~~~~
!!! error TS2698: Spread types may only be created from object types.
let a2 = <Component {...arg} prop1 />;
~~~~~~~~
!!! error TS2698: Spread types may only be created from object types.
}
declare function ComponentSpecific<U>(l: { prop: U }): JSX.Element;
declare function ComponentSpecific1<U>(l: { prop: U, "ignore-prop": number }): JSX.Element;
// Error, can only spread object type
function Bar<T extends { prop: number }>(arg: T) {
let a1 = <ComponentSpecific {...arg} ignore-prop="hi" />; // U is number
~~~~~~~~
!!! error TS2698: Spread types may only be created from object types.
let a2 = <ComponentSpecific1 {...arg} ignore-prop={10} />; // U is number
~~~~~~~~
!!! error TS2698: Spread types may only be created from object types.
let a3 = <ComponentSpecific {...arg} prop="hello" />; // U is "hello"
~~~~~~~~
!!! error TS2698: Spread types may only be created from object types.
}

View File

@ -0,0 +1,36 @@
//// [file.tsx]
import React = require('react')
// Error, can only spread object type
declare function Component<U>(l: U): JSX.Element;
function createComponent<T extends { prop: number }>(arg: T) {
let a1 = <Component {...arg} />;
let a2 = <Component {...arg} prop1 />;
}
declare function ComponentSpecific<U>(l: { prop: U }): JSX.Element;
declare function ComponentSpecific1<U>(l: { prop: U, "ignore-prop": number }): JSX.Element;
// Error, can only spread object type
function Bar<T extends { prop: number }>(arg: T) {
let a1 = <ComponentSpecific {...arg} ignore-prop="hi" />; // U is number
let a2 = <ComponentSpecific1 {...arg} ignore-prop={10} />; // U is number
let a3 = <ComponentSpecific {...arg} prop="hello" />; // U is "hello"
}
//// [file.jsx]
define(["require", "exports", "react"], function (require, exports, React) {
"use strict";
function createComponent(arg) {
var a1 = <Component {...arg}/>;
var a2 = <Component {...arg} prop1/>;
}
// Error, can only spread object type
function Bar(arg) {
var a1 = <ComponentSpecific {...arg} ignore-prop="hi"/>; // U is number
var a2 = <ComponentSpecific1 {...arg} ignore-prop={10}/>; // U is number
var a3 = <ComponentSpecific {...arg} prop="hello"/>; // U is "hello"
}
});

View File

@ -6,7 +6,6 @@
import React = require('react')
declare function ComponentWithTwoAttributes<K,V>(l: {key1: K, value: V}): JSX.Element;
// OK
@ -15,23 +14,6 @@ function Baz<T,U>(key1: T, value: U) {
let a1 = <ComponentWithTwoAttributes {...{key1, value: value}} key="Component" />
}
// OK
declare function Component<U>(l: U): JSX.Element;
function createComponent<T extends {prop: number}>(arg:T) {
let a1 = <Component {...arg} />;
let a2 = <Component {...arg} prop1 />;
}
declare function ComponentSpecific<U>(l: {prop: U}): JSX.Element;
declare function ComponentSpecific1<U>(l: {prop: U, "ignore-prop": number}): JSX.Element;
// OK
function Bar<T extends {prop: number}>(arg: T) {
let a1 = <ComponentSpecific {...arg} ignore-prop="hi" />; // U is number
let a2 = <ComponentSpecific1 {...arg} ignore-prop={10} />; // U is number
let a3 = <ComponentSpecific {...arg} prop="hello" />; // U is "hello"
}
declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;
// OK
@ -43,3 +25,12 @@ function createLink1(func: (a: number)=>boolean) {
let o = <Link func={func} />
}
interface InferParamProp<T> {
values: Array<T>;
selectHandler: (selectedVal: T) => void;
}
declare function InferParamComponent<T>(attr: InferParamProp<T>): JSX.Element;
// OK
let i = <InferParamComponent values={[1, 2, 3, 4]} selectHandler={(val) => { }} />;

View File

@ -24,4 +24,14 @@ declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;
// Error
function createLink(func: (a: number, b: string)=>void) {
let o = <Link func={func} />
}
}
interface InferParamProp<T> {
values: Array<T>;
selectHandler: (selectedVal: T) => void;
}
declare function InferParamComponent<T>(attr: InferParamProp<T>): JSX.Element;
// Error
let i = <InferParamComponent values={[1, 2, 3, 4]} selectHandler={(val: string) => { }} />;

View File

@ -0,0 +1,24 @@
// @filename: file.tsx
// @jsx: preserve
// @module: amd
// @noLib: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react')
// Error, can only spread object type
declare function Component<U>(l: U): JSX.Element;
function createComponent<T extends { prop: number }>(arg: T) {
let a1 = <Component {...arg} />;
let a2 = <Component {...arg} prop1 />;
}
declare function ComponentSpecific<U>(l: { prop: U }): JSX.Element;
declare function ComponentSpecific1<U>(l: { prop: U, "ignore-prop": number }): JSX.Element;
// Error, can only spread object type
function Bar<T extends { prop: number }>(arg: T) {
let a1 = <ComponentSpecific {...arg} ignore-prop="hi" />; // U is number
let a2 = <ComponentSpecific1 {...arg} ignore-prop={10} />; // U is number
let a3 = <ComponentSpecific {...arg} prop="hello" />; // U is "hello"
}