mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Merge pull request #15678 from Microsoft/master_allowSpreadGenericType
[Master] Allow spread generic type
This commit is contained in:
commit
cb723cf1dc
@ -13285,11 +13285,7 @@ namespace ts {
|
||||
attributesArray = [];
|
||||
attributesTable = createMap<Symbol>();
|
||||
}
|
||||
const exprType = checkExpression(attributeDecl.expression);
|
||||
if (!isValidSpreadType(exprType)) {
|
||||
error(attributeDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types);
|
||||
hasSpreadAnyType = true;
|
||||
}
|
||||
const exprType = getApparentType(checkExpression(attributeDecl.expression));
|
||||
if (isTypeAny(exprType)) {
|
||||
hasSpreadAnyType = true;
|
||||
}
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
tests/cases/conformance/jsx/file.tsx(17,16): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/jsx/file.tsx(21,16): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/jsx/file.tsx(25,16): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/jsx/file.tsx(21,16): error TS2322: Type '{ x: number; }' is not assignable to type 'Attribs1'.
|
||||
Types of property 'x' are incompatible.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/conformance/jsx/file.tsx(25,16): error TS2322: Type '{ y: string; }' is not assignable to type 'Attribs1'.
|
||||
Property 'x' is missing in type '{ y: string; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(29,8): error TS2322: Type '{}' is not assignable to type 'Attribs1'.
|
||||
Property 'x' is missing in type '{}'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsx/file.tsx (4 errors) ====
|
||||
==== tests/cases/conformance/jsx/file.tsx (3 errors) ====
|
||||
declare module JSX {
|
||||
interface Element { }
|
||||
interface IntrinsicElements {
|
||||
@ -23,20 +25,21 @@ tests/cases/conformance/jsx/file.tsx(29,8): error TS2322: Type '{}' is not assig
|
||||
|
||||
function make1<T extends {x: string}> (obj: T) {
|
||||
return <test1 {...obj} />; // OK
|
||||
~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
}
|
||||
|
||||
function make2<T extends {x: number}> (obj: T) {
|
||||
return <test1 {...obj} />; // Error (x is number, not string)
|
||||
~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
!!! error TS2322: Type '{ x: number; }' is not assignable to type 'Attribs1'.
|
||||
!!! error TS2322: Types of property 'x' are incompatible.
|
||||
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
}
|
||||
|
||||
function make3<T extends {y: string}> (obj: T) {
|
||||
return <test1 {...obj} />; // Error, missing x
|
||||
~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
!!! error TS2322: Type '{ y: string; }' is not assignable to type 'Attribs1'.
|
||||
!!! error TS2322: Property 'x' is missing in type '{ y: string; }'.
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
tests/cases/conformance/jsx/file.tsx(8,34): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/jsx/file.tsx(13,34): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/jsx/file.tsx(8,34): error TS2322: Type '{ ignore-prop: 10; prop: number; }' is not assignable to type 'IntrinsicAttributes & { prop: number; "ignore-prop": string; }'.
|
||||
Type '{ ignore-prop: 10; prop: number; }' is not assignable to type '{ prop: number; "ignore-prop": string; }'.
|
||||
Types of property '"ignore-prop"' are incompatible.
|
||||
Type '10' is not assignable to type 'string'.
|
||||
tests/cases/conformance/jsx/file.tsx(13,34): error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & { prop: {}; "ignore-prop": string; }'.
|
||||
Type '{}' is not assignable to type '{ prop: {}; "ignore-prop": string; }'.
|
||||
Property 'prop' is missing in type '{}'.
|
||||
tests/cases/conformance/jsx/file.tsx(20,19): error TS2322: Type '{ func: (a: number, b: string) => void; }' is not assignable to type 'IntrinsicAttributes & { func: (arg: number) => void; }'.
|
||||
Type '{ func: (a: number, b: string) => void; }' is not assignable to type '{ func: (arg: number) => void; }'.
|
||||
Types of property 'func' are incompatible.
|
||||
@ -19,15 +24,20 @@ tests/cases/conformance/jsx/file.tsx(31,10): error TS2453: The type argument for
|
||||
// Error
|
||||
function Bar<T extends {prop: number}>(arg: T) {
|
||||
let a1 = <ComponentSpecific1 {...arg} ignore-prop={10} />;
|
||||
~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ ignore-prop: 10; prop: number; }' is not assignable to type 'IntrinsicAttributes & { prop: number; "ignore-prop": string; }'.
|
||||
!!! error TS2322: Type '{ ignore-prop: 10; prop: number; }' is not assignable to type '{ prop: number; "ignore-prop": string; }'.
|
||||
!!! error TS2322: Types of property '"ignore-prop"' are incompatible.
|
||||
!!! error TS2322: Type '10' is not assignable to type 'string'.
|
||||
}
|
||||
|
||||
// Error
|
||||
function Baz<T>(arg: T) {
|
||||
let a0 = <ComponentSpecific1 {...arg} />
|
||||
~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
!!! error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & { prop: {}; "ignore-prop": string; }'.
|
||||
!!! error TS2322: Type '{}' is not assignable to type '{ prop: {}; "ignore-prop": string; }'.
|
||||
!!! error TS2322: Property 'prop' is missing in type '{}'.
|
||||
}
|
||||
|
||||
declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;
|
||||
|
||||
@ -1,50 +0,0 @@
|
||||
tests/cases/conformance/jsx/file.tsx(9,33): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/jsx/file.tsx(10,33): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/jsx/file.tsx(11,33): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/jsx/file.tsx(12,33): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/jsx/file.tsx(14,33): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/jsx/file.tsx(14,63): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/jsx/file.tsx(15,33): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/jsx/file.tsx(15,55): error TS2698: Spread types may only be created from object types.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsx/file.tsx (8 errors) ====
|
||||
import React = require('react')
|
||||
|
||||
declare function OverloadComponent<U>(): JSX.Element;
|
||||
declare function OverloadComponent<U>(attr: {b: U, a?: string, "ignore-prop": boolean}): JSX.Element;
|
||||
declare function OverloadComponent<T, U>(attr: {b: U, a: T}): JSX.Element;
|
||||
|
||||
// OK
|
||||
function Baz<T extends {b: number}, U extends {a: boolean, b:string}>(arg1: T, arg2: U) {
|
||||
let a0 = <OverloadComponent {...arg1} a="hello" ignore-prop />;
|
||||
~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
let a1 = <OverloadComponent {...arg2} ignore-pro="hello world" />;
|
||||
~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
let a2 = <OverloadComponent {...arg2} />;
|
||||
~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
let a3 = <OverloadComponent {...arg1} ignore-prop />;
|
||||
~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
let a4 = <OverloadComponent />;
|
||||
let a5 = <OverloadComponent {...arg2} ignore-prop="hello" {...arg1} />;
|
||||
~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
let a6 = <OverloadComponent {...arg2} ignore-prop {...arg1} />;
|
||||
~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
}
|
||||
|
||||
declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;
|
||||
declare function Link<U>(l: {func: (arg1:U, arg2: string)=>void}): JSX.Element;
|
||||
function createLink(func: (a: number)=>void) {
|
||||
let o = <Link func={func} />
|
||||
let o1 = <Link func={(a:number, b:string)=>{}} />;
|
||||
}
|
||||
@ -1,128 +1,127 @@
|
||||
=== tests/cases/conformance/jsx/file.tsx ===
|
||||
|
||||
import React = require('react')
|
||||
>React : Symbol(React, Decl(file.tsx, 0, 0))
|
||||
|
||||
declare function OverloadComponent<U>(): JSX.Element;
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 1, 31), Decl(file.tsx, 3, 53), Decl(file.tsx, 4, 101))
|
||||
>U : Symbol(U, Decl(file.tsx, 3, 35))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 0, 31), Decl(file.tsx, 2, 53), Decl(file.tsx, 3, 101))
|
||||
>U : Symbol(U, Decl(file.tsx, 2, 35))
|
||||
>JSX : Symbol(JSX, Decl(react.d.ts, 2352, 1))
|
||||
>Element : Symbol(JSX.Element, Decl(react.d.ts, 2355, 27))
|
||||
|
||||
declare function OverloadComponent<U>(attr: {b: U, a?: string, "ignore-prop": boolean}): JSX.Element;
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 1, 31), Decl(file.tsx, 3, 53), Decl(file.tsx, 4, 101))
|
||||
>U : Symbol(U, Decl(file.tsx, 4, 35))
|
||||
>attr : Symbol(attr, Decl(file.tsx, 4, 38))
|
||||
>b : Symbol(b, Decl(file.tsx, 4, 45))
|
||||
>U : Symbol(U, Decl(file.tsx, 4, 35))
|
||||
>a : Symbol(a, Decl(file.tsx, 4, 50))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 0, 31), Decl(file.tsx, 2, 53), Decl(file.tsx, 3, 101))
|
||||
>U : Symbol(U, Decl(file.tsx, 3, 35))
|
||||
>attr : Symbol(attr, Decl(file.tsx, 3, 38))
|
||||
>b : Symbol(b, Decl(file.tsx, 3, 45))
|
||||
>U : Symbol(U, Decl(file.tsx, 3, 35))
|
||||
>a : Symbol(a, Decl(file.tsx, 3, 50))
|
||||
>JSX : Symbol(JSX, Decl(react.d.ts, 2352, 1))
|
||||
>Element : Symbol(JSX.Element, Decl(react.d.ts, 2355, 27))
|
||||
|
||||
declare function OverloadComponent<T, U>(attr: {b: U, a: T}): JSX.Element;
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 1, 31), Decl(file.tsx, 3, 53), Decl(file.tsx, 4, 101))
|
||||
>T : Symbol(T, Decl(file.tsx, 5, 35))
|
||||
>U : Symbol(U, Decl(file.tsx, 5, 37))
|
||||
>attr : Symbol(attr, Decl(file.tsx, 5, 41))
|
||||
>b : Symbol(b, Decl(file.tsx, 5, 48))
|
||||
>U : Symbol(U, Decl(file.tsx, 5, 37))
|
||||
>a : Symbol(a, Decl(file.tsx, 5, 53))
|
||||
>T : Symbol(T, Decl(file.tsx, 5, 35))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 0, 31), Decl(file.tsx, 2, 53), Decl(file.tsx, 3, 101))
|
||||
>T : Symbol(T, Decl(file.tsx, 4, 35))
|
||||
>U : Symbol(U, Decl(file.tsx, 4, 37))
|
||||
>attr : Symbol(attr, Decl(file.tsx, 4, 41))
|
||||
>b : Symbol(b, Decl(file.tsx, 4, 48))
|
||||
>U : Symbol(U, Decl(file.tsx, 4, 37))
|
||||
>a : Symbol(a, Decl(file.tsx, 4, 53))
|
||||
>T : Symbol(T, Decl(file.tsx, 4, 35))
|
||||
>JSX : Symbol(JSX, Decl(react.d.ts, 2352, 1))
|
||||
>Element : Symbol(JSX.Element, Decl(react.d.ts, 2355, 27))
|
||||
|
||||
// OK
|
||||
function Baz<T extends {b: number}, U extends {a: boolean, b:string}>(arg1: T, arg2: U) {
|
||||
>Baz : Symbol(Baz, Decl(file.tsx, 5, 74))
|
||||
>T : Symbol(T, Decl(file.tsx, 8, 13))
|
||||
>b : Symbol(b, Decl(file.tsx, 8, 24))
|
||||
>U : Symbol(U, Decl(file.tsx, 8, 35))
|
||||
>a : Symbol(a, Decl(file.tsx, 8, 47))
|
||||
>b : Symbol(b, Decl(file.tsx, 8, 58))
|
||||
>arg1 : Symbol(arg1, Decl(file.tsx, 8, 70))
|
||||
>T : Symbol(T, Decl(file.tsx, 8, 13))
|
||||
>arg2 : Symbol(arg2, Decl(file.tsx, 8, 78))
|
||||
>U : Symbol(U, Decl(file.tsx, 8, 35))
|
||||
>Baz : Symbol(Baz, Decl(file.tsx, 4, 74))
|
||||
>T : Symbol(T, Decl(file.tsx, 7, 13))
|
||||
>b : Symbol(b, Decl(file.tsx, 7, 24))
|
||||
>U : Symbol(U, Decl(file.tsx, 7, 35))
|
||||
>a : Symbol(a, Decl(file.tsx, 7, 47))
|
||||
>b : Symbol(b, Decl(file.tsx, 7, 58))
|
||||
>arg1 : Symbol(arg1, Decl(file.tsx, 7, 70))
|
||||
>T : Symbol(T, Decl(file.tsx, 7, 13))
|
||||
>arg2 : Symbol(arg2, Decl(file.tsx, 7, 78))
|
||||
>U : Symbol(U, Decl(file.tsx, 7, 35))
|
||||
|
||||
let a0 = <OverloadComponent {...arg1} a="hello" ignore-prop />;
|
||||
>a0 : Symbol(a0, Decl(file.tsx, 9, 7))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 1, 31), Decl(file.tsx, 3, 53), Decl(file.tsx, 4, 101))
|
||||
>arg1 : Symbol(arg1, Decl(file.tsx, 8, 70))
|
||||
>a : Symbol(a, Decl(file.tsx, 9, 41))
|
||||
>ignore-prop : Symbol(ignore-prop, Decl(file.tsx, 9, 51))
|
||||
>a0 : Symbol(a0, Decl(file.tsx, 8, 7))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 0, 31), Decl(file.tsx, 2, 53), Decl(file.tsx, 3, 101))
|
||||
>arg1 : Symbol(arg1, Decl(file.tsx, 7, 70))
|
||||
>a : Symbol(a, Decl(file.tsx, 8, 41))
|
||||
>ignore-prop : Symbol(ignore-prop, Decl(file.tsx, 8, 51))
|
||||
|
||||
let a1 = <OverloadComponent {...arg2} ignore-pro="hello world" />;
|
||||
>a1 : Symbol(a1, Decl(file.tsx, 10, 7))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 1, 31), Decl(file.tsx, 3, 53), Decl(file.tsx, 4, 101))
|
||||
>arg2 : Symbol(arg2, Decl(file.tsx, 8, 78))
|
||||
>ignore-pro : Symbol(ignore-pro, Decl(file.tsx, 10, 41))
|
||||
>a1 : Symbol(a1, Decl(file.tsx, 9, 7))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 0, 31), Decl(file.tsx, 2, 53), Decl(file.tsx, 3, 101))
|
||||
>arg2 : Symbol(arg2, Decl(file.tsx, 7, 78))
|
||||
>ignore-pro : Symbol(ignore-pro, Decl(file.tsx, 9, 41))
|
||||
|
||||
let a2 = <OverloadComponent {...arg2} />;
|
||||
>a2 : Symbol(a2, Decl(file.tsx, 11, 7))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 1, 31), Decl(file.tsx, 3, 53), Decl(file.tsx, 4, 101))
|
||||
>arg2 : Symbol(arg2, Decl(file.tsx, 8, 78))
|
||||
>a2 : Symbol(a2, Decl(file.tsx, 10, 7))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 0, 31), Decl(file.tsx, 2, 53), Decl(file.tsx, 3, 101))
|
||||
>arg2 : Symbol(arg2, Decl(file.tsx, 7, 78))
|
||||
|
||||
let a3 = <OverloadComponent {...arg1} ignore-prop />;
|
||||
>a3 : Symbol(a3, Decl(file.tsx, 12, 7))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 1, 31), Decl(file.tsx, 3, 53), Decl(file.tsx, 4, 101))
|
||||
>arg1 : Symbol(arg1, Decl(file.tsx, 8, 70))
|
||||
>ignore-prop : Symbol(ignore-prop, Decl(file.tsx, 12, 41))
|
||||
>a3 : Symbol(a3, Decl(file.tsx, 11, 7))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 0, 31), Decl(file.tsx, 2, 53), Decl(file.tsx, 3, 101))
|
||||
>arg1 : Symbol(arg1, Decl(file.tsx, 7, 70))
|
||||
>ignore-prop : Symbol(ignore-prop, Decl(file.tsx, 11, 41))
|
||||
|
||||
let a4 = <OverloadComponent />;
|
||||
>a4 : Symbol(a4, Decl(file.tsx, 13, 7))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 1, 31), Decl(file.tsx, 3, 53), Decl(file.tsx, 4, 101))
|
||||
>a4 : Symbol(a4, Decl(file.tsx, 12, 7))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 0, 31), Decl(file.tsx, 2, 53), Decl(file.tsx, 3, 101))
|
||||
|
||||
let a5 = <OverloadComponent {...arg2} ignore-prop="hello" {...arg1} />;
|
||||
>a5 : Symbol(a5, Decl(file.tsx, 14, 7))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 1, 31), Decl(file.tsx, 3, 53), Decl(file.tsx, 4, 101))
|
||||
>arg2 : Symbol(arg2, Decl(file.tsx, 8, 78))
|
||||
>ignore-prop : Symbol(ignore-prop, Decl(file.tsx, 14, 41))
|
||||
>arg1 : Symbol(arg1, Decl(file.tsx, 8, 70))
|
||||
>a5 : Symbol(a5, Decl(file.tsx, 13, 7))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 0, 31), Decl(file.tsx, 2, 53), Decl(file.tsx, 3, 101))
|
||||
>arg2 : Symbol(arg2, Decl(file.tsx, 7, 78))
|
||||
>ignore-prop : Symbol(ignore-prop, Decl(file.tsx, 13, 41))
|
||||
>arg1 : Symbol(arg1, Decl(file.tsx, 7, 70))
|
||||
|
||||
let a6 = <OverloadComponent {...arg2} ignore-prop {...arg1} />;
|
||||
>a6 : Symbol(a6, Decl(file.tsx, 15, 7))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 1, 31), Decl(file.tsx, 3, 53), Decl(file.tsx, 4, 101))
|
||||
>arg2 : Symbol(arg2, Decl(file.tsx, 8, 78))
|
||||
>ignore-prop : Symbol(ignore-prop, Decl(file.tsx, 15, 41))
|
||||
>arg1 : Symbol(arg1, Decl(file.tsx, 8, 70))
|
||||
>a6 : Symbol(a6, Decl(file.tsx, 14, 7))
|
||||
>OverloadComponent : Symbol(OverloadComponent, Decl(file.tsx, 0, 31), Decl(file.tsx, 2, 53), Decl(file.tsx, 3, 101))
|
||||
>arg2 : Symbol(arg2, Decl(file.tsx, 7, 78))
|
||||
>ignore-prop : Symbol(ignore-prop, Decl(file.tsx, 14, 41))
|
||||
>arg1 : Symbol(arg1, Decl(file.tsx, 7, 70))
|
||||
}
|
||||
|
||||
declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;
|
||||
>Link : Symbol(Link, Decl(file.tsx, 16, 1), Decl(file.tsx, 18, 65))
|
||||
>U : Symbol(U, Decl(file.tsx, 18, 22))
|
||||
>l : Symbol(l, Decl(file.tsx, 18, 25))
|
||||
>func : Symbol(func, Decl(file.tsx, 18, 29))
|
||||
>arg : Symbol(arg, Decl(file.tsx, 18, 36))
|
||||
>U : Symbol(U, Decl(file.tsx, 18, 22))
|
||||
>Link : Symbol(Link, Decl(file.tsx, 15, 1), Decl(file.tsx, 17, 65))
|
||||
>U : Symbol(U, Decl(file.tsx, 17, 22))
|
||||
>l : Symbol(l, Decl(file.tsx, 17, 25))
|
||||
>func : Symbol(func, Decl(file.tsx, 17, 29))
|
||||
>arg : Symbol(arg, Decl(file.tsx, 17, 36))
|
||||
>U : Symbol(U, Decl(file.tsx, 17, 22))
|
||||
>JSX : Symbol(JSX, Decl(react.d.ts, 2352, 1))
|
||||
>Element : Symbol(JSX.Element, Decl(react.d.ts, 2355, 27))
|
||||
|
||||
declare function Link<U>(l: {func: (arg1:U, arg2: string)=>void}): JSX.Element;
|
||||
>Link : Symbol(Link, Decl(file.tsx, 16, 1), Decl(file.tsx, 18, 65))
|
||||
>U : Symbol(U, Decl(file.tsx, 19, 22))
|
||||
>l : Symbol(l, Decl(file.tsx, 19, 25))
|
||||
>func : Symbol(func, Decl(file.tsx, 19, 29))
|
||||
>arg1 : Symbol(arg1, Decl(file.tsx, 19, 36))
|
||||
>U : Symbol(U, Decl(file.tsx, 19, 22))
|
||||
>arg2 : Symbol(arg2, Decl(file.tsx, 19, 43))
|
||||
>Link : Symbol(Link, Decl(file.tsx, 15, 1), Decl(file.tsx, 17, 65))
|
||||
>U : Symbol(U, Decl(file.tsx, 18, 22))
|
||||
>l : Symbol(l, Decl(file.tsx, 18, 25))
|
||||
>func : Symbol(func, Decl(file.tsx, 18, 29))
|
||||
>arg1 : Symbol(arg1, Decl(file.tsx, 18, 36))
|
||||
>U : Symbol(U, Decl(file.tsx, 18, 22))
|
||||
>arg2 : Symbol(arg2, Decl(file.tsx, 18, 43))
|
||||
>JSX : Symbol(JSX, Decl(react.d.ts, 2352, 1))
|
||||
>Element : Symbol(JSX.Element, Decl(react.d.ts, 2355, 27))
|
||||
|
||||
function createLink(func: (a: number)=>void) {
|
||||
>createLink : Symbol(createLink, Decl(file.tsx, 19, 79))
|
||||
>func : Symbol(func, Decl(file.tsx, 20, 20))
|
||||
>a : Symbol(a, Decl(file.tsx, 20, 27))
|
||||
>createLink : Symbol(createLink, Decl(file.tsx, 18, 79))
|
||||
>func : Symbol(func, Decl(file.tsx, 19, 20))
|
||||
>a : Symbol(a, Decl(file.tsx, 19, 27))
|
||||
|
||||
let o = <Link func={func} />
|
||||
>o : Symbol(o, Decl(file.tsx, 21, 7))
|
||||
>Link : Symbol(Link, Decl(file.tsx, 16, 1), Decl(file.tsx, 18, 65))
|
||||
>func : Symbol(func, Decl(file.tsx, 21, 17))
|
||||
>func : Symbol(func, Decl(file.tsx, 20, 20))
|
||||
>o : Symbol(o, Decl(file.tsx, 20, 7))
|
||||
>Link : Symbol(Link, Decl(file.tsx, 15, 1), Decl(file.tsx, 17, 65))
|
||||
>func : Symbol(func, Decl(file.tsx, 20, 17))
|
||||
>func : Symbol(func, Decl(file.tsx, 19, 20))
|
||||
|
||||
let o1 = <Link func={(a:number, b:string)=>{}} />;
|
||||
>o1 : Symbol(o1, Decl(file.tsx, 22, 7))
|
||||
>Link : Symbol(Link, Decl(file.tsx, 16, 1), Decl(file.tsx, 18, 65))
|
||||
>func : Symbol(func, Decl(file.tsx, 22, 18))
|
||||
>a : Symbol(a, Decl(file.tsx, 22, 26))
|
||||
>b : Symbol(b, Decl(file.tsx, 22, 35))
|
||||
>o1 : Symbol(o1, Decl(file.tsx, 21, 7))
|
||||
>Link : Symbol(Link, Decl(file.tsx, 15, 1), Decl(file.tsx, 17, 65))
|
||||
>func : Symbol(func, Decl(file.tsx, 21, 18))
|
||||
>a : Symbol(a, Decl(file.tsx, 21, 26))
|
||||
>b : Symbol(b, Decl(file.tsx, 21, 35))
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
=== tests/cases/conformance/jsx/file.tsx ===
|
||||
|
||||
import React = require('react')
|
||||
>React : typeof React
|
||||
|
||||
@ -131,8 +130,8 @@ function createLink(func: (a: number)=>void) {
|
||||
>o1 : JSX.Element
|
||||
><Link func={(a:number, b:string)=>{}} /> : JSX.Element
|
||||
>Link : { <U>(l: { func: (arg: U) => void; }): JSX.Element; <U>(l: { func: (arg1: U, arg2: string) => void; }): JSX.Element; }
|
||||
>func : (a: number, b: string) => void
|
||||
>(a:number, b:string)=>{} : (a: number, b: string) => void
|
||||
>func : (a: number, b: string) => any
|
||||
>(a:number, b:string)=>{} : (a: number, b: string) => any
|
||||
>a : number
|
||||
>b : string
|
||||
}
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
tests/cases/conformance/jsx/file.tsx(9,33): error TS2322: Type '{ a: number; }' is not assignable to type 'IntrinsicAttributes & { b: {}; a: number; }'.
|
||||
Type '{ a: number; }' is not assignable to type '{ b: {}; a: number; }'.
|
||||
Property 'b' is missing in type '{ a: number; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(10,33): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/jsx/file.tsx(10,33): error TS2322: Type '{ b: number; }' is not assignable to type 'IntrinsicAttributes & { b: number; a: {}; }'.
|
||||
Type '{ b: number; }' is not assignable to type '{ b: number; a: {}; }'.
|
||||
Property 'a' is missing in type '{ b: number; }'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsx/file.tsx (2 errors) ====
|
||||
@ -19,6 +21,8 @@ tests/cases/conformance/jsx/file.tsx(10,33): error TS2698: Spread types may only
|
||||
!!! error TS2322: Type '{ a: number; }' is not assignable to type '{ b: {}; a: number; }'.
|
||||
!!! error TS2322: Property 'b' is missing in type '{ a: number; }'.
|
||||
let a2 = <OverloadComponent {...arg1} ignore-prop /> // missing a
|
||||
~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ b: number; }' is not assignable to type 'IntrinsicAttributes & { b: number; a: {}; }'.
|
||||
!!! error TS2322: Type '{ b: number; }' is not assignable to type '{ b: number; a: {}; }'.
|
||||
!!! error TS2322: Property 'a' is missing in type '{ b: number; }'.
|
||||
}
|
||||
@ -1,37 +1,24 @@
|
||||
tests/cases/conformance/jsx/file.tsx(6,25): error TS2698: Spread types may only be created from object types.
|
||||
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(15,33): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/jsx/file.tsx(16,34): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/jsx/file.tsx(17,33): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/jsx/file.tsx(16,42): error TS2339: Property 'prop1' does not exist on type 'IntrinsicAttributes & { prop: number; }'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsx/file.tsx (5 errors) ====
|
||||
==== tests/cases/conformance/jsx/file.tsx (1 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.
|
||||
let a4 = <ComponentSpecific {...arg} prop1="hello" />; // U is "hello"
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2339: Property 'prop1' does not exist on type 'IntrinsicAttributes & { prop: number; }'.
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
//// [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} />;
|
||||
@ -11,11 +10,11 @@ function createComponent<T extends { prop: number }>(arg: T) {
|
||||
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"
|
||||
let a4 = <ComponentSpecific {...arg} prop1="hello" />; // U is "hello"
|
||||
}
|
||||
|
||||
|
||||
@ -27,10 +26,10 @@ define(["require", "exports", "react"], function (require, exports, React) {
|
||||
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"
|
||||
var a4 = <ComponentSpecific {...arg} prop1="hello"/>; // U is "hello"
|
||||
}
|
||||
});
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
|
||||
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} />;
|
||||
@ -16,9 +15,9 @@ function createComponent<T extends { prop: number }>(arg: T) {
|
||||
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"
|
||||
let a4 = <ComponentSpecific {...arg} prop1="hello" />; // U is "hello"
|
||||
}
|
||||
|
||||
@ -14,6 +14,6 @@
|
||||
//// }
|
||||
|
||||
verify.quickInfos({
|
||||
1: "function ComponentSpecific<{}>(l: {\n prop: {};\n}): any",
|
||||
2: "function ComponentSpecific<{}>(l: {\n prop: {};\n}): any"
|
||||
1: "function ComponentSpecific<number>(l: {\n prop: number;\n}): any",
|
||||
2: "function ComponentSpecific<\"hello\">(l: {\n prop: \"hello\";\n}): any"
|
||||
});
|
||||
|
||||
@ -15,15 +15,15 @@
|
||||
//// let a3 = <Overloa/*4*/dComponent {...arg1} ignore-prop />;
|
||||
//// let a4 = <Overloa/*5*/dComponent />;
|
||||
//// let a5 = <Overloa/*6*/dComponent {...arg2} ignore-prop="hello" {...arg1} />;
|
||||
//// let a6 = <Overloa/*7*/dComponent {...arg2} ignore-prop {...arg1} />;
|
||||
//// let a6 = <Overloa/*7*/dComponent {...arg1} ignore-prop {...arg2} />;
|
||||
//// }
|
||||
|
||||
verify.quickInfos({
|
||||
1: "function OverloadComponent(): any (+2 overloads)",
|
||||
2: "function OverloadComponent(): any (+2 overloads)",
|
||||
3: "function OverloadComponent(): any (+2 overloads)",
|
||||
4: "function OverloadComponent(): any (+2 overloads)",
|
||||
1: "function OverloadComponent<number>(attr: {\n b: number;\n a?: string;\n \"ignore-prop\": boolean;\n}): any (+2 overloads)",
|
||||
2: "function OverloadComponent<boolean, string>(attr: {\n b: string;\n a: boolean;\n}): any (+2 overloads)",
|
||||
3: "function OverloadComponent<boolean, string>(attr: {\n b: string;\n a: boolean;\n}): any (+2 overloads)",
|
||||
4: "function OverloadComponent<number>(attr: {\n b: number;\n a?: string;\n \"ignore-prop\": boolean;\n}): any (+2 overloads)",
|
||||
5: "function OverloadComponent(): any (+2 overloads)",
|
||||
6: "function OverloadComponent(): any (+2 overloads)",
|
||||
7: "function OverloadComponent(): any (+2 overloads)"
|
||||
6: "function OverloadComponent<boolean, number>(attr: {\n b: number;\n a: boolean;\n}): any (+2 overloads)",
|
||||
7: "function OverloadComponent<boolean, string>(attr: {\n b: string;\n a: boolean;\n}): any (+2 overloads)"
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user