diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.errors.txt b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.errors.txt deleted file mode 100644 index dd628c6de0e..00000000000 --- a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.errors.txt +++ /dev/null @@ -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(l: {key1: K, value: V}): JSX.Element; - - // OK - function Baz(key1: T, value: U) { - let a0 = - let a1 = - } - - // OK - declare function Component(l: U): JSX.Element; - function createComponent(arg:T) { - let a1 = ; - ~~~~~~~~ -!!! error TS2698: Spread types may only be created from object types. - let a2 = ; - ~~~~~~~~ -!!! error TS2698: Spread types may only be created from object types. - } - - declare function ComponentSpecific(l: {prop: U}): JSX.Element; - declare function ComponentSpecific1(l: {prop: U, "ignore-prop": number}): JSX.Element; - - // OK - function Bar(arg: T) { - let a1 = ; // U is number - ~~~~~~~~ -!!! error TS2698: Spread types may only be created from object types. - let a2 = ; // U is number - ~~~~~~~~ -!!! error TS2698: Spread types may only be created from object types. - let a3 = ; // U is "hello" - ~~~~~~~~ -!!! error TS2698: Spread types may only be created from object types. - } - - declare function Link(l: {func: (arg: U)=>void}): JSX.Element; - - // OK - function createLink(func: (a: number)=>void) { - let o = - } - - function createLink1(func: (a: number)=>boolean) { - let o = - } - - \ No newline at end of file diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.js b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.js index ab9171b8ed1..3824c49af4a 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.js +++ b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.js @@ -2,7 +2,6 @@ import React = require('react') - declare function ComponentWithTwoAttributes(l: {key1: K, value: V}): JSX.Element; // OK @@ -11,23 +10,6 @@ function Baz(key1: T, value: U) { let a1 = } -// OK -declare function Component(l: U): JSX.Element; -function createComponent(arg:T) { - let a1 = ; - let a2 = ; -} - -declare function ComponentSpecific(l: {prop: U}): JSX.Element; -declare function ComponentSpecific1(l: {prop: U, "ignore-prop": number}): JSX.Element; - -// OK -function Bar(arg: T) { - let a1 = ; // U is number - let a2 = ; // U is number - let a3 = ; // U is "hello" -} - declare function Link(l: {func: (arg: U)=>void}): JSX.Element; // OK @@ -39,7 +21,15 @@ function createLink1(func: (a: number)=>boolean) { let o = } - +interface InferParamProp { + values: Array; + selectHandler: (selectedVal: T) => void; +} + +declare function InferParamComponent(attr: InferParamProp): JSX.Element; + +// OK +let i = { }} />; //// [file.jsx] define(["require", "exports", "react"], function (require, exports, React) { @@ -49,16 +39,6 @@ define(["require", "exports", "react"], function (require, exports, React) { var a0 = ; var a1 = ; } - function createComponent(arg) { - var a1 = ; - var a2 = ; - } - // OK - function Bar(arg) { - var a1 = ; // U is number - var a2 = ; // U is number - var a3 = ; // U is "hello" - } // OK function createLink(func) { var o = ; @@ -66,4 +46,6 @@ define(["require", "exports", "react"], function (require, exports, React) { function createLink1(func) { var o = ; } + // OK + var i = ; }); diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.symbols b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.symbols index 88654281891..f5e8e97dd76 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.symbols +++ b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.symbols @@ -3,152 +3,109 @@ import React = require('react') >React : Symbol(React, Decl(file.tsx, 0, 0)) - declare function ComponentWithTwoAttributes(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(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 = ->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 = ->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(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(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 = ; ->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 = ; ->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(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(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(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 = ; // 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 = ; // 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 = ; // 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(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 = ->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 = ->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 { +>InferParamProp : Symbol(InferParamProp, Decl(file.tsx, 20, 1)) +>T : Symbol(T, Decl(file.tsx, 22, 25)) + + values: Array; +>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(attr: InferParamProp): 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 = { }} />; +>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)) diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.types b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.types index c1bf05c0fa5..3136ea8adfa 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.types @@ -3,7 +3,6 @@ import React = require('react') >React : typeof React - declare function ComponentWithTwoAttributes(l: {key1: K, value: V}): JSX.Element; >ComponentWithTwoAttributes : (l: { key1: K; value: V; }) => JSX.Element >K : K @@ -46,85 +45,6 @@ function Baz(key1: T, value: U) { >key : string } -// OK -declare function Component(l: U): JSX.Element; ->Component : (l: U) => JSX.Element ->U : U ->l : U ->U : U ->JSX : any ->Element : JSX.Element - -function createComponent(arg:T) { ->createComponent : (arg: T) => void ->T : T ->prop : number ->arg : T ->T : T - - let a1 = ; ->a1 : JSX.Element -> : JSX.Element ->Component : (l: U) => JSX.Element ->arg : T - - let a2 = ; ->a2 : JSX.Element -> : JSX.Element ->Component : (l: U) => JSX.Element ->arg : T ->prop1 : true -} - -declare function ComponentSpecific(l: {prop: U}): JSX.Element; ->ComponentSpecific : (l: { prop: U; }) => JSX.Element ->U : U ->l : { prop: U; } ->prop : U ->U : U ->JSX : any ->Element : JSX.Element - -declare function ComponentSpecific1(l: {prop: U, "ignore-prop": number}): JSX.Element; ->ComponentSpecific1 : (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(arg: T) { ->Bar : (arg: T) => void ->T : T ->prop : number ->arg : T ->T : T - - let a1 = ; // U is number ->a1 : JSX.Element -> : JSX.Element ->ComponentSpecific : (l: { prop: U; }) => JSX.Element ->arg : T ->ignore-prop : string - - let a2 = ; // U is number ->a2 : JSX.Element -> : JSX.Element ->ComponentSpecific1 : (l: { prop: U; "ignore-prop": number; }) => JSX.Element ->arg : T ->ignore-prop : number ->10 : 10 - - let a3 = ; // U is "hello" ->a3 : JSX.Element -> : JSX.Element ->ComponentSpecific : (l: { prop: U; }) => JSX.Element ->arg : T ->prop : string -} - declare function Link(l: {func: (arg: U)=>void}): JSX.Element; >Link : (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 { +>InferParamProp : InferParamProp +>T : T + + values: Array; +>values : T[] +>Array : T[] +>T : T + + selectHandler: (selectedVal: T) => void; +>selectHandler : (selectedVal: T) => void +>selectedVal : T +>T : T +} + +declare function InferParamComponent(attr: InferParamProp): JSX.Element; +>InferParamComponent : (attr: InferParamProp) => JSX.Element +>T : T +>attr : InferParamProp +>InferParamProp : InferParamProp +>T : T +>JSX : any +>Element : JSX.Element + +// OK +let i = { }} />; +>i : JSX.Element +> { }} /> : JSX.Element +>InferParamComponent : (attr: InferParamProp) => 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 diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments2.errors.txt b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments2.errors.txt index 98fa75d99a1..359c0a3c007 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments2.errors.txt +++ b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments2.errors.txt @@ -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'. - } \ No newline at end of file + } + + interface InferParamProp { + values: Array; + selectHandler: (selectedVal: T) => void; + } + + declare function InferParamComponent(attr: InferParamProp): JSX.Element; + + // Error + let i = { }} />; + ~~~~~~~~~~~~~~~~~~~ +!!! 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'. + \ No newline at end of file diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments2.js b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments2.js index a42f7ac1768..30e85c21d4a 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments2.js +++ b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments2.js @@ -20,7 +20,18 @@ declare function Link(l: {func: (arg: U)=>void}): JSX.Element; // Error function createLink(func: (a: number, b: string)=>void) { let o = -} +} + +interface InferParamProp { + values: Array; + selectHandler: (selectedVal: T) => void; +} + +declare function InferParamComponent(attr: InferParamProp): JSX.Element; + +// Error +let i = { }} />; + //// [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 = ; } + // Error + var i = ; }); diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments5.errors.txt b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments5.errors.txt new file mode 100644 index 00000000000..a86cd2b20c4 --- /dev/null +++ b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments5.errors.txt @@ -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(l: U): JSX.Element; + function createComponent(arg: T) { + let a1 = ; + ~~~~~~~~ +!!! error TS2698: Spread types may only be created from object types. + let a2 = ; + ~~~~~~~~ +!!! error TS2698: Spread types may only be created from object types. + } + + declare function ComponentSpecific(l: { prop: U }): JSX.Element; + declare function ComponentSpecific1(l: { prop: U, "ignore-prop": number }): JSX.Element; + + // Error, can only spread object type + function Bar(arg: T) { + let a1 = ; // U is number + ~~~~~~~~ +!!! error TS2698: Spread types may only be created from object types. + let a2 = ; // U is number + ~~~~~~~~ +!!! error TS2698: Spread types may only be created from object types. + let a3 = ; // U is "hello" + ~~~~~~~~ +!!! error TS2698: Spread types may only be created from object types. + } + \ No newline at end of file diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments5.js b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments5.js new file mode 100644 index 00000000000..f7766dc3f5f --- /dev/null +++ b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments5.js @@ -0,0 +1,36 @@ +//// [file.tsx] + +import React = require('react') + +// Error, can only spread object type +declare function Component(l: U): JSX.Element; +function createComponent(arg: T) { + let a1 = ; + let a2 = ; +} + +declare function ComponentSpecific(l: { prop: U }): JSX.Element; +declare function ComponentSpecific1(l: { prop: U, "ignore-prop": number }): JSX.Element; + +// Error, can only spread object type +function Bar(arg: T) { + let a1 = ; // U is number + let a2 = ; // U is number + let a3 = ; // U is "hello" +} + + +//// [file.jsx] +define(["require", "exports", "react"], function (require, exports, React) { + "use strict"; + function createComponent(arg) { + var a1 = ; + var a2 = ; + } + // Error, can only spread object type + function Bar(arg) { + var a1 = ; // U is number + var a2 = ; // U is number + var a3 = ; // U is "hello" + } +}); diff --git a/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments1.tsx b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments1.tsx index 3cae8471229..f910ef665e6 100644 --- a/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments1.tsx +++ b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments1.tsx @@ -6,7 +6,6 @@ import React = require('react') - declare function ComponentWithTwoAttributes(l: {key1: K, value: V}): JSX.Element; // OK @@ -15,23 +14,6 @@ function Baz(key1: T, value: U) { let a1 = } -// OK -declare function Component(l: U): JSX.Element; -function createComponent(arg:T) { - let a1 = ; - let a2 = ; -} - -declare function ComponentSpecific(l: {prop: U}): JSX.Element; -declare function ComponentSpecific1(l: {prop: U, "ignore-prop": number}): JSX.Element; - -// OK -function Bar(arg: T) { - let a1 = ; // U is number - let a2 = ; // U is number - let a3 = ; // U is "hello" -} - declare function Link(l: {func: (arg: U)=>void}): JSX.Element; // OK @@ -43,3 +25,12 @@ function createLink1(func: (a: number)=>boolean) { let o = } +interface InferParamProp { + values: Array; + selectHandler: (selectedVal: T) => void; +} + +declare function InferParamComponent(attr: InferParamProp): JSX.Element; + +// OK +let i = { }} />; \ No newline at end of file diff --git a/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments2.tsx b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments2.tsx index e264ffde2ff..e2a5f818428 100644 --- a/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments2.tsx +++ b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments2.tsx @@ -24,4 +24,14 @@ declare function Link(l: {func: (arg: U)=>void}): JSX.Element; // Error function createLink(func: (a: number, b: string)=>void) { let o = -} \ No newline at end of file +} + +interface InferParamProp { + values: Array; + selectHandler: (selectedVal: T) => void; +} + +declare function InferParamComponent(attr: InferParamProp): JSX.Element; + +// Error +let i = { }} />; diff --git a/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments5.tsx b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments5.tsx new file mode 100644 index 00000000000..527eb689ddb --- /dev/null +++ b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments5.tsx @@ -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(l: U): JSX.Element; +function createComponent(arg: T) { + let a1 = ; + let a2 = ; +} + +declare function ComponentSpecific(l: { prop: U }): JSX.Element; +declare function ComponentSpecific1(l: { prop: U, "ignore-prop": number }): JSX.Element; + +// Error, can only spread object type +function Bar(arg: T) { + let a1 = ; // U is number + let a2 = ; // U is number + let a3 = ; // U is "hello" +}