mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Merge pull request #12552 from Microsoft/spreadRestIntersectionAndUnions
Spread & rest over intersection and unions
This commit is contained in:
commit
4c9bdb932a
@ -3054,7 +3054,15 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getRestType(source: Type, properties: PropertyName[], symbol: Symbol): Type {
|
||||
Debug.assert(!!(source.flags & TypeFlags.Object), "Rest types only support object types right now.");
|
||||
source = filterType(source, t => !(t.flags & TypeFlags.Nullable));
|
||||
if (source.flags & TypeFlags.Never) {
|
||||
return emptyObjectType;
|
||||
}
|
||||
|
||||
if (source.flags & TypeFlags.Union) {
|
||||
return mapType(source, t => getRestType(t, properties, symbol));
|
||||
}
|
||||
|
||||
const members = createMap<Symbol>();
|
||||
const names = createMap<true>();
|
||||
for (const name of properties) {
|
||||
@ -3095,7 +3103,7 @@ namespace ts {
|
||||
let type: Type;
|
||||
if (pattern.kind === SyntaxKind.ObjectBindingPattern) {
|
||||
if (declaration.dotDotDotToken) {
|
||||
if (!(parentType.flags & TypeFlags.Object)) {
|
||||
if (!isValidSpreadType(parentType)) {
|
||||
error(declaration, Diagnostics.Rest_types_may_only_be_created_from_object_types);
|
||||
return unknownType;
|
||||
}
|
||||
@ -6110,11 +6118,25 @@ namespace ts {
|
||||
* this function should be called in a left folding style, with left = previous result of getSpreadType
|
||||
* and right = the new element to be spread.
|
||||
*/
|
||||
function getSpreadType(left: Type, right: Type, isFromObjectLiteral: boolean): ResolvedType | IntrinsicType {
|
||||
Debug.assert(!!(left.flags & (TypeFlags.Object | TypeFlags.Any)) && !!(right.flags & (TypeFlags.Object | TypeFlags.Any)), "Only object types may be spread.");
|
||||
function getSpreadType(left: Type, right: Type, isFromObjectLiteral: boolean): Type {
|
||||
if (left.flags & TypeFlags.Any || right.flags & TypeFlags.Any) {
|
||||
return anyType;
|
||||
}
|
||||
left = filterType(left, t => !(t.flags & TypeFlags.Nullable));
|
||||
if (left.flags & TypeFlags.Never) {
|
||||
return right;
|
||||
}
|
||||
right = filterType(right, t => !(t.flags & TypeFlags.Nullable));
|
||||
if (right.flags & TypeFlags.Never) {
|
||||
return left;
|
||||
}
|
||||
if (left.flags & TypeFlags.Union) {
|
||||
return mapType(left, t => getSpreadType(t, right, isFromObjectLiteral));
|
||||
}
|
||||
if (right.flags & TypeFlags.Union) {
|
||||
return mapType(right, t => getSpreadType(left, t, isFromObjectLiteral));
|
||||
}
|
||||
|
||||
const members = createMap<Symbol>();
|
||||
const skippedPrivateMembers = createMap<boolean>();
|
||||
let stringIndexInfo: IndexInfo;
|
||||
@ -11446,7 +11468,7 @@ namespace ts {
|
||||
typeFlags = 0;
|
||||
}
|
||||
const type = checkExpression((memberDecl as SpreadAssignment).expression);
|
||||
if (!(type.flags & (TypeFlags.Object | TypeFlags.Any))) {
|
||||
if (!isValidSpreadType(type)) {
|
||||
error(memberDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types);
|
||||
return unknownType;
|
||||
}
|
||||
@ -11524,6 +11546,12 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isValidSpreadType(type: Type): boolean {
|
||||
return !!(type.flags & (TypeFlags.Any | TypeFlags.Null | TypeFlags.Undefined) ||
|
||||
type.flags & TypeFlags.Object && !isGenericMappedType(type) ||
|
||||
type.flags & TypeFlags.UnionOrIntersection && !forEach((<UnionOrIntersectionType>type).types, t => !isValidSpreadType(t)));
|
||||
}
|
||||
|
||||
function checkJsxSelfClosingElement(node: JsxSelfClosingElement) {
|
||||
checkJsxOpeningLikeElement(node);
|
||||
return jsxElementType || anyType;
|
||||
|
||||
@ -459,7 +459,7 @@ namespace ts {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (typeof Object.getOwnPropertySymbols === "function")
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
||||
t[p[i]] = s[p[i]];
|
||||
return t;
|
||||
|
||||
@ -43,7 +43,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (typeof Object.getOwnPropertySymbols === "function")
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
||||
t[p[i]] = s[p[i]];
|
||||
return t;
|
||||
|
||||
@ -19,7 +19,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (typeof Object.getOwnPropertySymbols === "function")
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
||||
t[p[i]] = s[p[i]];
|
||||
return t;
|
||||
|
||||
@ -27,7 +27,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (typeof Object.getOwnPropertySymbols === "function")
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
||||
t[p[i]] = s[p[i]];
|
||||
return t;
|
||||
|
||||
@ -23,7 +23,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (typeof Object.getOwnPropertySymbols === "function")
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
||||
t[p[i]] = s[p[i]];
|
||||
return t;
|
||||
|
||||
@ -22,7 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (typeof Object.getOwnPropertySymbols === "function")
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
||||
t[p[i]] = s[p[i]];
|
||||
return t;
|
||||
|
||||
@ -7,20 +7,18 @@ tests/cases/conformance/types/spread/objectSpreadNegative.ts(25,1): error TS2322
|
||||
Property 's' is missing in type '{ b: boolean; }'.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(28,36): error TS2300: Duplicate identifier 'b'.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(28,53): error TS2300: Duplicate identifier 'b'.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(32,20): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(33,24): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(34,19): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(35,19): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(37,20): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(39,19): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(44,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '{}' has no compatible call signatures.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(48,12): error TS2339: Property 'b' does not exist on type '{}'.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(54,9): error TS2339: Property 'm' does not exist on type '{ p: number; }'.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(58,14): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(61,14): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(32,19): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(33,19): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(35,20): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(37,19): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(42,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '{}' has no compatible call signatures.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(46,12): error TS2339: Property 'b' does not exist on type '{}'.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(52,9): error TS2339: Property 'm' does not exist on type '{ p: number; }'.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(56,14): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/conformance/types/spread/objectSpreadNegative.ts(59,14): error TS2698: Spread types may only be created from object types.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/spread/objectSpreadNegative.ts (17 errors) ====
|
||||
==== tests/cases/conformance/types/spread/objectSpreadNegative.ts (15 errors) ====
|
||||
let o = { a: 1, b: 'no' }
|
||||
|
||||
/// private propagates
|
||||
@ -66,13 +64,7 @@ tests/cases/conformance/types/spread/objectSpreadNegative.ts(61,14): error TS269
|
||||
!!! error TS2300: Duplicate identifier 'b'.
|
||||
let duplicatedSpread = { ...o, ...o }
|
||||
|
||||
// null, undefined and primitives are not allowed
|
||||
let spreadNull = { ...null };
|
||||
~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
let spreadUndefind = { ...undefined };
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
// primitives are not allowed
|
||||
let spreadNum = { ...12 };
|
||||
~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
|
||||
@ -29,9 +29,7 @@ spread = b; // error, missing 's'
|
||||
let duplicated = { b: 'bad', ...o, b: 'bad', ...o2, b: 'bad' }
|
||||
let duplicatedSpread = { ...o, ...o }
|
||||
|
||||
// null, undefined and primitives are not allowed
|
||||
let spreadNull = { ...null };
|
||||
let spreadUndefind = { ...undefined };
|
||||
// primitives are not allowed
|
||||
let spreadNum = { ...12 };
|
||||
let spreadSum = { ...1 + 1 };
|
||||
spreadSum.toFixed(); // error, no methods from number
|
||||
@ -108,9 +106,7 @@ spread = b; // error, missing 's'
|
||||
// literal repeats are not allowed, but spread repeats are fine
|
||||
var duplicated = __assign({ b: 'bad' }, o, { b: 'bad' }, o2, { b: 'bad' });
|
||||
var duplicatedSpread = __assign({}, o, o);
|
||||
// null, undefined and primitives are not allowed
|
||||
var spreadNull = __assign({}, null);
|
||||
var spreadUndefind = __assign({}, undefined);
|
||||
// primitives are not allowed
|
||||
var spreadNum = __assign({}, 12);
|
||||
var spreadSum = __assign({}, 1 + 1);
|
||||
spreadSum.toFixed(); // error, no methods from number
|
||||
|
||||
20
tests/baselines/reference/restIntersection.js
Normal file
20
tests/baselines/reference/restIntersection.js
Normal file
@ -0,0 +1,20 @@
|
||||
//// [restIntersection.ts]
|
||||
var intersection: { x: number, y: number } & { w: string, z: string };
|
||||
|
||||
var rest1: { y: number, w: string, z: string };
|
||||
var {x, ...rest1 } = intersection;
|
||||
|
||||
|
||||
//// [restIntersection.js]
|
||||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
||||
t[p[i]] = s[p[i]];
|
||||
return t;
|
||||
};
|
||||
var intersection;
|
||||
var rest1;
|
||||
var x = intersection.x, rest1 = __rest(intersection, ["x"]);
|
||||
19
tests/baselines/reference/restIntersection.symbols
Normal file
19
tests/baselines/reference/restIntersection.symbols
Normal file
@ -0,0 +1,19 @@
|
||||
=== tests/cases/compiler/restIntersection.ts ===
|
||||
var intersection: { x: number, y: number } & { w: string, z: string };
|
||||
>intersection : Symbol(intersection, Decl(restIntersection.ts, 0, 3))
|
||||
>x : Symbol(x, Decl(restIntersection.ts, 0, 19))
|
||||
>y : Symbol(y, Decl(restIntersection.ts, 0, 30))
|
||||
>w : Symbol(w, Decl(restIntersection.ts, 0, 46))
|
||||
>z : Symbol(z, Decl(restIntersection.ts, 0, 57))
|
||||
|
||||
var rest1: { y: number, w: string, z: string };
|
||||
>rest1 : Symbol(rest1, Decl(restIntersection.ts, 2, 3), Decl(restIntersection.ts, 3, 7))
|
||||
>y : Symbol(y, Decl(restIntersection.ts, 2, 12))
|
||||
>w : Symbol(w, Decl(restIntersection.ts, 2, 23))
|
||||
>z : Symbol(z, Decl(restIntersection.ts, 2, 34))
|
||||
|
||||
var {x, ...rest1 } = intersection;
|
||||
>x : Symbol(x, Decl(restIntersection.ts, 3, 5))
|
||||
>rest1 : Symbol(rest1, Decl(restIntersection.ts, 2, 3), Decl(restIntersection.ts, 3, 7))
|
||||
>intersection : Symbol(intersection, Decl(restIntersection.ts, 0, 3))
|
||||
|
||||
19
tests/baselines/reference/restIntersection.types
Normal file
19
tests/baselines/reference/restIntersection.types
Normal file
@ -0,0 +1,19 @@
|
||||
=== tests/cases/compiler/restIntersection.ts ===
|
||||
var intersection: { x: number, y: number } & { w: string, z: string };
|
||||
>intersection : { x: number; y: number; } & { w: string; z: string; }
|
||||
>x : number
|
||||
>y : number
|
||||
>w : string
|
||||
>z : string
|
||||
|
||||
var rest1: { y: number, w: string, z: string };
|
||||
>rest1 : { y: number; w: string; z: string; }
|
||||
>y : number
|
||||
>w : string
|
||||
>z : string
|
||||
|
||||
var {x, ...rest1 } = intersection;
|
||||
>x : number
|
||||
>rest1 : { y: number; w: string; z: string; }
|
||||
>intersection : { x: number; y: number; } & { w: string; z: string; }
|
||||
|
||||
104
tests/baselines/reference/restInvalidArgumentType.errors.txt
Normal file
104
tests/baselines/reference/restInvalidArgumentType.errors.txt
Normal file
@ -0,0 +1,104 @@
|
||||
tests/cases/compiler/restInvalidArgumentType.ts(31,13): error TS2700: Rest types may only be created from object types.
|
||||
tests/cases/compiler/restInvalidArgumentType.ts(33,13): error TS2700: Rest types may only be created from object types.
|
||||
tests/cases/compiler/restInvalidArgumentType.ts(35,13): error TS2700: Rest types may only be created from object types.
|
||||
tests/cases/compiler/restInvalidArgumentType.ts(36,13): error TS2700: Rest types may only be created from object types.
|
||||
tests/cases/compiler/restInvalidArgumentType.ts(38,13): error TS2700: Rest types may only be created from object types.
|
||||
tests/cases/compiler/restInvalidArgumentType.ts(41,13): error TS2700: Rest types may only be created from object types.
|
||||
tests/cases/compiler/restInvalidArgumentType.ts(42,13): error TS2700: Rest types may only be created from object types.
|
||||
tests/cases/compiler/restInvalidArgumentType.ts(44,13): error TS2700: Rest types may only be created from object types.
|
||||
tests/cases/compiler/restInvalidArgumentType.ts(45,13): error TS2700: Rest types may only be created from object types.
|
||||
tests/cases/compiler/restInvalidArgumentType.ts(47,13): error TS2700: Rest types may only be created from object types.
|
||||
tests/cases/compiler/restInvalidArgumentType.ts(48,13): error TS2700: Rest types may only be created from object types.
|
||||
tests/cases/compiler/restInvalidArgumentType.ts(55,13): error TS2700: Rest types may only be created from object types.
|
||||
tests/cases/compiler/restInvalidArgumentType.ts(56,13): error TS2700: Rest types may only be created from object types.
|
||||
tests/cases/compiler/restInvalidArgumentType.ts(58,13): error TS2700: Rest types may only be created from object types.
|
||||
|
||||
|
||||
==== tests/cases/compiler/restInvalidArgumentType.ts (14 errors) ====
|
||||
enum E { v1, v2 };
|
||||
|
||||
function f<T extends { b: string }>(p1: T, p2: T[]) {
|
||||
var t: T;
|
||||
|
||||
var i: T["b"];
|
||||
var k: keyof T;
|
||||
|
||||
var mapped_generic: {[P in keyof T]: T[P]};
|
||||
var mapped: {[P in "b"]: T[P]};
|
||||
|
||||
var union_generic: T | { a: number };
|
||||
var union_primitive: { a: number } | number;
|
||||
|
||||
var intersection_generic: T & { a: number };
|
||||
var intersection_premitive: { a: number } | string;
|
||||
|
||||
var num: number;
|
||||
var str: number;
|
||||
|
||||
var u: undefined;
|
||||
var n: null;
|
||||
|
||||
var a: any;
|
||||
|
||||
var literal_string: "string";
|
||||
var literal_number: 42;
|
||||
|
||||
var e: E;
|
||||
|
||||
var {...r1} = p1; // Error, generic type paramterre
|
||||
~~
|
||||
!!! error TS2700: Rest types may only be created from object types.
|
||||
var {...r2} = p2; // OK
|
||||
var {...r3} = t; // Error, generic type paramter
|
||||
~~
|
||||
!!! error TS2700: Rest types may only be created from object types.
|
||||
|
||||
var {...r4} = i; // Error, index access
|
||||
~~
|
||||
!!! error TS2700: Rest types may only be created from object types.
|
||||
var {...r5} = k; // Error, index
|
||||
~~
|
||||
!!! error TS2700: Rest types may only be created from object types.
|
||||
|
||||
var {...r6} = mapped_generic; // Error, generic mapped object type
|
||||
~~
|
||||
!!! error TS2700: Rest types may only be created from object types.
|
||||
var {...r7} = mapped; // OK, non-generic mapped type
|
||||
|
||||
var {...r8} = union_generic; // Error, union with generic type parameter
|
||||
~~
|
||||
!!! error TS2700: Rest types may only be created from object types.
|
||||
var {...r9} = union_primitive; // Error, union with generic type parameter
|
||||
~~
|
||||
!!! error TS2700: Rest types may only be created from object types.
|
||||
|
||||
var {...r10} = intersection_generic; // Error, intersection with generic type parameter
|
||||
~~~
|
||||
!!! error TS2700: Rest types may only be created from object types.
|
||||
var {...r11} = intersection_premitive; // Error, intersection with generic type parameter
|
||||
~~~
|
||||
!!! error TS2700: Rest types may only be created from object types.
|
||||
|
||||
var {...r12} = num; // Error
|
||||
~~~
|
||||
!!! error TS2700: Rest types may only be created from object types.
|
||||
var {...r13} = str; // Error
|
||||
~~~
|
||||
!!! error TS2700: Rest types may only be created from object types.
|
||||
|
||||
var {...r14} = u; // OK
|
||||
var {...r15} = n; // OK
|
||||
|
||||
var {...r16} = a; // OK
|
||||
|
||||
var {...r17} = literal_string; // Error
|
||||
~~~
|
||||
!!! error TS2700: Rest types may only be created from object types.
|
||||
var {...r18} = literal_number; // Error
|
||||
~~~
|
||||
!!! error TS2700: Rest types may only be created from object types.
|
||||
|
||||
var {...r19} = e; // Error, enum
|
||||
~~~
|
||||
!!! error TS2700: Rest types may only be created from object types.
|
||||
}
|
||||
115
tests/baselines/reference/restInvalidArgumentType.js
Normal file
115
tests/baselines/reference/restInvalidArgumentType.js
Normal file
@ -0,0 +1,115 @@
|
||||
//// [restInvalidArgumentType.ts]
|
||||
enum E { v1, v2 };
|
||||
|
||||
function f<T extends { b: string }>(p1: T, p2: T[]) {
|
||||
var t: T;
|
||||
|
||||
var i: T["b"];
|
||||
var k: keyof T;
|
||||
|
||||
var mapped_generic: {[P in keyof T]: T[P]};
|
||||
var mapped: {[P in "b"]: T[P]};
|
||||
|
||||
var union_generic: T | { a: number };
|
||||
var union_primitive: { a: number } | number;
|
||||
|
||||
var intersection_generic: T & { a: number };
|
||||
var intersection_premitive: { a: number } | string;
|
||||
|
||||
var num: number;
|
||||
var str: number;
|
||||
|
||||
var u: undefined;
|
||||
var n: null;
|
||||
|
||||
var a: any;
|
||||
|
||||
var literal_string: "string";
|
||||
var literal_number: 42;
|
||||
|
||||
var e: E;
|
||||
|
||||
var {...r1} = p1; // Error, generic type paramterre
|
||||
var {...r2} = p2; // OK
|
||||
var {...r3} = t; // Error, generic type paramter
|
||||
|
||||
var {...r4} = i; // Error, index access
|
||||
var {...r5} = k; // Error, index
|
||||
|
||||
var {...r6} = mapped_generic; // Error, generic mapped object type
|
||||
var {...r7} = mapped; // OK, non-generic mapped type
|
||||
|
||||
var {...r8} = union_generic; // Error, union with generic type parameter
|
||||
var {...r9} = union_primitive; // Error, union with generic type parameter
|
||||
|
||||
var {...r10} = intersection_generic; // Error, intersection with generic type parameter
|
||||
var {...r11} = intersection_premitive; // Error, intersection with generic type parameter
|
||||
|
||||
var {...r12} = num; // Error
|
||||
var {...r13} = str; // Error
|
||||
|
||||
var {...r14} = u; // OK
|
||||
var {...r15} = n; // OK
|
||||
|
||||
var {...r16} = a; // OK
|
||||
|
||||
var {...r17} = literal_string; // Error
|
||||
var {...r18} = literal_number; // Error
|
||||
|
||||
var {...r19} = e; // Error, enum
|
||||
}
|
||||
|
||||
//// [restInvalidArgumentType.js]
|
||||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
||||
t[p[i]] = s[p[i]];
|
||||
return t;
|
||||
};
|
||||
var E;
|
||||
(function (E) {
|
||||
E[E["v1"] = 0] = "v1";
|
||||
E[E["v2"] = 1] = "v2";
|
||||
})(E || (E = {}));
|
||||
;
|
||||
function f(p1, p2) {
|
||||
var t;
|
||||
var i;
|
||||
var k;
|
||||
var mapped_generic;
|
||||
var mapped;
|
||||
var union_generic;
|
||||
var union_primitive;
|
||||
var intersection_generic;
|
||||
var intersection_premitive;
|
||||
var num;
|
||||
var str;
|
||||
var u;
|
||||
var n;
|
||||
var a;
|
||||
var literal_string;
|
||||
var literal_number;
|
||||
var e;
|
||||
var r1 = __rest(p1, []); // Error, generic type paramterre
|
||||
var r2 = __rest(p2, []); // OK
|
||||
var r3 = __rest(t, []); // Error, generic type paramter
|
||||
var r4 = __rest(i, []); // Error, index access
|
||||
var r5 = __rest(k, []); // Error, index
|
||||
var r6 = __rest(mapped_generic, []); // Error, generic mapped object type
|
||||
var r7 = __rest(mapped, []); // OK, non-generic mapped type
|
||||
var r8 = __rest(union_generic, []); // Error, union with generic type parameter
|
||||
var r9 = __rest(union_primitive, []); // Error, union with generic type parameter
|
||||
var r10 = __rest(intersection_generic, []); // Error, intersection with generic type parameter
|
||||
var r11 = __rest(intersection_premitive, []); // Error, intersection with generic type parameter
|
||||
var r12 = __rest(num, []); // Error
|
||||
var r13 = __rest(str, []); // Error
|
||||
var r14 = __rest(u, []); // OK
|
||||
var r15 = __rest(n, []); // OK
|
||||
var r16 = __rest(a, []); // OK
|
||||
var r17 = __rest(literal_string, []); // Error
|
||||
var r18 = __rest(literal_number, []); // Error
|
||||
var r19 = __rest(e, []); // Error, enum
|
||||
}
|
||||
36
tests/baselines/reference/restUnion.js
Normal file
36
tests/baselines/reference/restUnion.js
Normal file
@ -0,0 +1,36 @@
|
||||
//// [restUnion.ts]
|
||||
var union: { a: number, c: boolean } | { a: string, b: string };
|
||||
|
||||
var rest1: { c: boolean } | { b: string };
|
||||
var {a, ...rest1 } = union;
|
||||
|
||||
|
||||
var undefinedUnion: { n: number } | undefined;
|
||||
var rest2: {};
|
||||
var {n, ...rest2 } = undefinedUnion;
|
||||
|
||||
|
||||
var nullUnion: { n: number } | null;
|
||||
var rest3: {};
|
||||
var {n, ...rest3 } = nullUnion;
|
||||
|
||||
|
||||
//// [restUnion.js]
|
||||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
||||
t[p[i]] = s[p[i]];
|
||||
return t;
|
||||
};
|
||||
var union;
|
||||
var rest1;
|
||||
var a = union.a, rest1 = __rest(union, ["a"]);
|
||||
var undefinedUnion;
|
||||
var rest2;
|
||||
var n = undefinedUnion.n, rest2 = __rest(undefinedUnion, ["n"]);
|
||||
var nullUnion;
|
||||
var rest3;
|
||||
var n = nullUnion.n, rest3 = __rest(nullUnion, ["n"]);
|
||||
44
tests/baselines/reference/restUnion.symbols
Normal file
44
tests/baselines/reference/restUnion.symbols
Normal file
@ -0,0 +1,44 @@
|
||||
=== tests/cases/compiler/restUnion.ts ===
|
||||
var union: { a: number, c: boolean } | { a: string, b: string };
|
||||
>union : Symbol(union, Decl(restUnion.ts, 0, 3))
|
||||
>a : Symbol(a, Decl(restUnion.ts, 0, 12))
|
||||
>c : Symbol(c, Decl(restUnion.ts, 0, 23))
|
||||
>a : Symbol(a, Decl(restUnion.ts, 0, 40))
|
||||
>b : Symbol(b, Decl(restUnion.ts, 0, 51))
|
||||
|
||||
var rest1: { c: boolean } | { b: string };
|
||||
>rest1 : Symbol(rest1, Decl(restUnion.ts, 2, 3), Decl(restUnion.ts, 3, 7))
|
||||
>c : Symbol(c, Decl(restUnion.ts, 2, 12))
|
||||
>b : Symbol(b, Decl(restUnion.ts, 2, 29))
|
||||
|
||||
var {a, ...rest1 } = union;
|
||||
>a : Symbol(a, Decl(restUnion.ts, 3, 5))
|
||||
>rest1 : Symbol(rest1, Decl(restUnion.ts, 2, 3), Decl(restUnion.ts, 3, 7))
|
||||
>union : Symbol(union, Decl(restUnion.ts, 0, 3))
|
||||
|
||||
|
||||
var undefinedUnion: { n: number } | undefined;
|
||||
>undefinedUnion : Symbol(undefinedUnion, Decl(restUnion.ts, 6, 3))
|
||||
>n : Symbol(n, Decl(restUnion.ts, 6, 21))
|
||||
|
||||
var rest2: {};
|
||||
>rest2 : Symbol(rest2, Decl(restUnion.ts, 7, 3), Decl(restUnion.ts, 8, 7))
|
||||
|
||||
var {n, ...rest2 } = undefinedUnion;
|
||||
>n : Symbol(n, Decl(restUnion.ts, 8, 5), Decl(restUnion.ts, 13, 5))
|
||||
>rest2 : Symbol(rest2, Decl(restUnion.ts, 7, 3), Decl(restUnion.ts, 8, 7))
|
||||
>undefinedUnion : Symbol(undefinedUnion, Decl(restUnion.ts, 6, 3))
|
||||
|
||||
|
||||
var nullUnion: { n: number } | null;
|
||||
>nullUnion : Symbol(nullUnion, Decl(restUnion.ts, 11, 3))
|
||||
>n : Symbol(n, Decl(restUnion.ts, 11, 16))
|
||||
|
||||
var rest3: {};
|
||||
>rest3 : Symbol(rest3, Decl(restUnion.ts, 12, 3), Decl(restUnion.ts, 13, 7))
|
||||
|
||||
var {n, ...rest3 } = nullUnion;
|
||||
>n : Symbol(n, Decl(restUnion.ts, 8, 5), Decl(restUnion.ts, 13, 5))
|
||||
>rest3 : Symbol(rest3, Decl(restUnion.ts, 12, 3), Decl(restUnion.ts, 13, 7))
|
||||
>nullUnion : Symbol(nullUnion, Decl(restUnion.ts, 11, 3))
|
||||
|
||||
45
tests/baselines/reference/restUnion.types
Normal file
45
tests/baselines/reference/restUnion.types
Normal file
@ -0,0 +1,45 @@
|
||||
=== tests/cases/compiler/restUnion.ts ===
|
||||
var union: { a: number, c: boolean } | { a: string, b: string };
|
||||
>union : { a: number; c: boolean; } | { a: string; b: string; }
|
||||
>a : number
|
||||
>c : boolean
|
||||
>a : string
|
||||
>b : string
|
||||
|
||||
var rest1: { c: boolean } | { b: string };
|
||||
>rest1 : { c: boolean; } | { b: string; }
|
||||
>c : boolean
|
||||
>b : string
|
||||
|
||||
var {a, ...rest1 } = union;
|
||||
>a : string | number
|
||||
>rest1 : { c: boolean; } | { b: string; }
|
||||
>union : { a: number; c: boolean; } | { a: string; b: string; }
|
||||
|
||||
|
||||
var undefinedUnion: { n: number } | undefined;
|
||||
>undefinedUnion : { n: number; }
|
||||
>n : number
|
||||
|
||||
var rest2: {};
|
||||
>rest2 : {}
|
||||
|
||||
var {n, ...rest2 } = undefinedUnion;
|
||||
>n : number
|
||||
>rest2 : {}
|
||||
>undefinedUnion : { n: number; }
|
||||
|
||||
|
||||
var nullUnion: { n: number } | null;
|
||||
>nullUnion : { n: number; }
|
||||
>n : number
|
||||
>null : null
|
||||
|
||||
var rest3: {};
|
||||
>rest3 : {}
|
||||
|
||||
var {n, ...rest3 } = nullUnion;
|
||||
>n : number
|
||||
>rest3 : {}
|
||||
>nullUnion : { n: number; }
|
||||
|
||||
38
tests/baselines/reference/restUnion2.js
Normal file
38
tests/baselines/reference/restUnion2.js
Normal file
@ -0,0 +1,38 @@
|
||||
//// [restUnion2.ts]
|
||||
|
||||
declare const undefinedUnion: { n: number } | undefined;
|
||||
var rest2: { n: number };
|
||||
var {...rest2 } = undefinedUnion;
|
||||
|
||||
|
||||
declare const nullUnion: { n: number } | null;
|
||||
var rest3: { n: number };
|
||||
var {...rest3 } = nullUnion;
|
||||
|
||||
|
||||
declare const nullAndUndefinedUnion: null | undefined;
|
||||
var rest4: { };
|
||||
var {...rest4 } = nullAndUndefinedUnion;
|
||||
|
||||
declare const unionWithIntersection: ({ n: number } & { s: string }) & undefined | null;
|
||||
var rest5: { n: number, s: string };
|
||||
var {...rest5 } = unionWithIntersection;
|
||||
|
||||
//// [restUnion2.js]
|
||||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
||||
t[p[i]] = s[p[i]];
|
||||
return t;
|
||||
};
|
||||
var rest2;
|
||||
var rest2 = __rest(undefinedUnion, []);
|
||||
var rest3;
|
||||
var rest3 = __rest(nullUnion, []);
|
||||
var rest4;
|
||||
var rest4 = __rest(nullAndUndefinedUnion, []);
|
||||
var rest5;
|
||||
var rest5 = __rest(unionWithIntersection, []);
|
||||
52
tests/baselines/reference/restUnion2.symbols
Normal file
52
tests/baselines/reference/restUnion2.symbols
Normal file
@ -0,0 +1,52 @@
|
||||
=== tests/cases/compiler/restUnion2.ts ===
|
||||
|
||||
declare const undefinedUnion: { n: number } | undefined;
|
||||
>undefinedUnion : Symbol(undefinedUnion, Decl(restUnion2.ts, 1, 13))
|
||||
>n : Symbol(n, Decl(restUnion2.ts, 1, 31))
|
||||
|
||||
var rest2: { n: number };
|
||||
>rest2 : Symbol(rest2, Decl(restUnion2.ts, 2, 3), Decl(restUnion2.ts, 3, 5))
|
||||
>n : Symbol(n, Decl(restUnion2.ts, 2, 12))
|
||||
|
||||
var {...rest2 } = undefinedUnion;
|
||||
>rest2 : Symbol(rest2, Decl(restUnion2.ts, 2, 3), Decl(restUnion2.ts, 3, 5))
|
||||
>undefinedUnion : Symbol(undefinedUnion, Decl(restUnion2.ts, 1, 13))
|
||||
|
||||
|
||||
declare const nullUnion: { n: number } | null;
|
||||
>nullUnion : Symbol(nullUnion, Decl(restUnion2.ts, 6, 13))
|
||||
>n : Symbol(n, Decl(restUnion2.ts, 6, 26))
|
||||
|
||||
var rest3: { n: number };
|
||||
>rest3 : Symbol(rest3, Decl(restUnion2.ts, 7, 3), Decl(restUnion2.ts, 8, 5))
|
||||
>n : Symbol(n, Decl(restUnion2.ts, 7, 12))
|
||||
|
||||
var {...rest3 } = nullUnion;
|
||||
>rest3 : Symbol(rest3, Decl(restUnion2.ts, 7, 3), Decl(restUnion2.ts, 8, 5))
|
||||
>nullUnion : Symbol(nullUnion, Decl(restUnion2.ts, 6, 13))
|
||||
|
||||
|
||||
declare const nullAndUndefinedUnion: null | undefined;
|
||||
>nullAndUndefinedUnion : Symbol(nullAndUndefinedUnion, Decl(restUnion2.ts, 11, 13))
|
||||
|
||||
var rest4: { };
|
||||
>rest4 : Symbol(rest4, Decl(restUnion2.ts, 12, 3), Decl(restUnion2.ts, 13, 5))
|
||||
|
||||
var {...rest4 } = nullAndUndefinedUnion;
|
||||
>rest4 : Symbol(rest4, Decl(restUnion2.ts, 12, 3), Decl(restUnion2.ts, 13, 5))
|
||||
>nullAndUndefinedUnion : Symbol(nullAndUndefinedUnion, Decl(restUnion2.ts, 11, 13))
|
||||
|
||||
declare const unionWithIntersection: ({ n: number } & { s: string }) & undefined | null;
|
||||
>unionWithIntersection : Symbol(unionWithIntersection, Decl(restUnion2.ts, 15, 13))
|
||||
>n : Symbol(n, Decl(restUnion2.ts, 15, 39))
|
||||
>s : Symbol(s, Decl(restUnion2.ts, 15, 55))
|
||||
|
||||
var rest5: { n: number, s: string };
|
||||
>rest5 : Symbol(rest5, Decl(restUnion2.ts, 16, 3), Decl(restUnion2.ts, 17, 5))
|
||||
>n : Symbol(n, Decl(restUnion2.ts, 16, 12))
|
||||
>s : Symbol(s, Decl(restUnion2.ts, 16, 23))
|
||||
|
||||
var {...rest5 } = unionWithIntersection;
|
||||
>rest5 : Symbol(rest5, Decl(restUnion2.ts, 16, 3), Decl(restUnion2.ts, 17, 5))
|
||||
>unionWithIntersection : Symbol(unionWithIntersection, Decl(restUnion2.ts, 15, 13))
|
||||
|
||||
55
tests/baselines/reference/restUnion2.types
Normal file
55
tests/baselines/reference/restUnion2.types
Normal file
@ -0,0 +1,55 @@
|
||||
=== tests/cases/compiler/restUnion2.ts ===
|
||||
|
||||
declare const undefinedUnion: { n: number } | undefined;
|
||||
>undefinedUnion : { n: number; } | undefined
|
||||
>n : number
|
||||
|
||||
var rest2: { n: number };
|
||||
>rest2 : { n: number; }
|
||||
>n : number
|
||||
|
||||
var {...rest2 } = undefinedUnion;
|
||||
>rest2 : { n: number; }
|
||||
>undefinedUnion : { n: number; } | undefined
|
||||
|
||||
|
||||
declare const nullUnion: { n: number } | null;
|
||||
>nullUnion : { n: number; } | null
|
||||
>n : number
|
||||
>null : null
|
||||
|
||||
var rest3: { n: number };
|
||||
>rest3 : { n: number; }
|
||||
>n : number
|
||||
|
||||
var {...rest3 } = nullUnion;
|
||||
>rest3 : { n: number; }
|
||||
>nullUnion : { n: number; } | null
|
||||
|
||||
|
||||
declare const nullAndUndefinedUnion: null | undefined;
|
||||
>nullAndUndefinedUnion : null | undefined
|
||||
>null : null
|
||||
|
||||
var rest4: { };
|
||||
>rest4 : {}
|
||||
|
||||
var {...rest4 } = nullAndUndefinedUnion;
|
||||
>rest4 : {}
|
||||
>nullAndUndefinedUnion : null | undefined
|
||||
|
||||
declare const unionWithIntersection: ({ n: number } & { s: string }) & undefined | null;
|
||||
>unionWithIntersection : ({ n: number; } & { s: string; } & undefined) | null
|
||||
>n : number
|
||||
>s : string
|
||||
>null : null
|
||||
|
||||
var rest5: { n: number, s: string };
|
||||
>rest5 : { n: number; s: string; }
|
||||
>n : number
|
||||
>s : string
|
||||
|
||||
var {...rest5 } = unionWithIntersection;
|
||||
>rest5 : { n: number; s: string; }
|
||||
>unionWithIntersection : ({ n: number; } & { s: string; } & undefined) | null
|
||||
|
||||
23
tests/baselines/reference/spreadIntersection.js
Normal file
23
tests/baselines/reference/spreadIntersection.js
Normal file
@ -0,0 +1,23 @@
|
||||
//// [spreadIntersection.ts]
|
||||
var intersection: { a: number } & { b: string };
|
||||
|
||||
var o1: { a: number, b: string };
|
||||
var o1 = { ...intersection };
|
||||
|
||||
var o2: { a: number, b: string, c: boolean };
|
||||
var o2 = { ...intersection, c: false };
|
||||
|
||||
//// [spreadIntersection.js]
|
||||
var __assign = (this && this.__assign) || Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
var intersection;
|
||||
var o1;
|
||||
var o1 = __assign({}, intersection);
|
||||
var o2;
|
||||
var o2 = __assign({}, intersection, { c: false });
|
||||
26
tests/baselines/reference/spreadIntersection.symbols
Normal file
26
tests/baselines/reference/spreadIntersection.symbols
Normal file
@ -0,0 +1,26 @@
|
||||
=== tests/cases/compiler/spreadIntersection.ts ===
|
||||
var intersection: { a: number } & { b: string };
|
||||
>intersection : Symbol(intersection, Decl(spreadIntersection.ts, 0, 3))
|
||||
>a : Symbol(a, Decl(spreadIntersection.ts, 0, 19))
|
||||
>b : Symbol(b, Decl(spreadIntersection.ts, 0, 35))
|
||||
|
||||
var o1: { a: number, b: string };
|
||||
>o1 : Symbol(o1, Decl(spreadIntersection.ts, 2, 3), Decl(spreadIntersection.ts, 3, 3))
|
||||
>a : Symbol(a, Decl(spreadIntersection.ts, 2, 9))
|
||||
>b : Symbol(b, Decl(spreadIntersection.ts, 2, 20))
|
||||
|
||||
var o1 = { ...intersection };
|
||||
>o1 : Symbol(o1, Decl(spreadIntersection.ts, 2, 3), Decl(spreadIntersection.ts, 3, 3))
|
||||
>intersection : Symbol(intersection, Decl(spreadIntersection.ts, 0, 3))
|
||||
|
||||
var o2: { a: number, b: string, c: boolean };
|
||||
>o2 : Symbol(o2, Decl(spreadIntersection.ts, 5, 3), Decl(spreadIntersection.ts, 6, 3))
|
||||
>a : Symbol(a, Decl(spreadIntersection.ts, 5, 9))
|
||||
>b : Symbol(b, Decl(spreadIntersection.ts, 5, 20))
|
||||
>c : Symbol(c, Decl(spreadIntersection.ts, 5, 31))
|
||||
|
||||
var o2 = { ...intersection, c: false };
|
||||
>o2 : Symbol(o2, Decl(spreadIntersection.ts, 5, 3), Decl(spreadIntersection.ts, 6, 3))
|
||||
>intersection : Symbol(intersection, Decl(spreadIntersection.ts, 0, 3))
|
||||
>c : Symbol(c, Decl(spreadIntersection.ts, 6, 27))
|
||||
|
||||
29
tests/baselines/reference/spreadIntersection.types
Normal file
29
tests/baselines/reference/spreadIntersection.types
Normal file
@ -0,0 +1,29 @@
|
||||
=== tests/cases/compiler/spreadIntersection.ts ===
|
||||
var intersection: { a: number } & { b: string };
|
||||
>intersection : { a: number; } & { b: string; }
|
||||
>a : number
|
||||
>b : string
|
||||
|
||||
var o1: { a: number, b: string };
|
||||
>o1 : { a: number; b: string; }
|
||||
>a : number
|
||||
>b : string
|
||||
|
||||
var o1 = { ...intersection };
|
||||
>o1 : { a: number; b: string; }
|
||||
>{ ...intersection } : { a: number; b: string; }
|
||||
>intersection : { a: number; } & { b: string; }
|
||||
|
||||
var o2: { a: number, b: string, c: boolean };
|
||||
>o2 : { a: number; b: string; c: boolean; }
|
||||
>a : number
|
||||
>b : string
|
||||
>c : boolean
|
||||
|
||||
var o2 = { ...intersection, c: false };
|
||||
>o2 : { a: number; b: string; c: boolean; }
|
||||
>{ ...intersection, c: false } : { c: boolean; a: number; b: string; }
|
||||
>intersection : { a: number; } & { b: string; }
|
||||
>c : boolean
|
||||
>false : false
|
||||
|
||||
104
tests/baselines/reference/spreadInvalidArgumentType.errors.txt
Normal file
104
tests/baselines/reference/spreadInvalidArgumentType.errors.txt
Normal file
@ -0,0 +1,104 @@
|
||||
tests/cases/compiler/spreadInvalidArgumentType.ts(31,16): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/compiler/spreadInvalidArgumentType.ts(33,16): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/compiler/spreadInvalidArgumentType.ts(35,16): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/compiler/spreadInvalidArgumentType.ts(36,16): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/compiler/spreadInvalidArgumentType.ts(38,16): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/compiler/spreadInvalidArgumentType.ts(41,16): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/compiler/spreadInvalidArgumentType.ts(42,16): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/compiler/spreadInvalidArgumentType.ts(44,17): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/compiler/spreadInvalidArgumentType.ts(45,17): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/compiler/spreadInvalidArgumentType.ts(47,17): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/compiler/spreadInvalidArgumentType.ts(48,17): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/compiler/spreadInvalidArgumentType.ts(55,17): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/compiler/spreadInvalidArgumentType.ts(56,17): error TS2698: Spread types may only be created from object types.
|
||||
tests/cases/compiler/spreadInvalidArgumentType.ts(58,17): error TS2698: Spread types may only be created from object types.
|
||||
|
||||
|
||||
==== tests/cases/compiler/spreadInvalidArgumentType.ts (14 errors) ====
|
||||
enum E { v1, v2 };
|
||||
|
||||
function f<T extends { b: string }>(p1: T, p2: T[]) {
|
||||
var t: T;
|
||||
|
||||
var i: T["b"];
|
||||
var k: keyof T;
|
||||
|
||||
var mapped_generic: {[P in keyof T]: T[P]};
|
||||
var mapped: {[P in "b"]: T[P]};
|
||||
|
||||
var union_generic: T | { a: number };
|
||||
var union_primitive: { a: number } | number;
|
||||
|
||||
var intersection_generic: T & { a: number };
|
||||
var intersection_premitive: { a: number } | string;
|
||||
|
||||
var num: number;
|
||||
var str: number;
|
||||
|
||||
var u: undefined;
|
||||
var n: null;
|
||||
|
||||
var a: any;
|
||||
|
||||
var literal_string: "string";
|
||||
var literal_number: 42;
|
||||
|
||||
var e: E;
|
||||
|
||||
var o1 = { ...p1 }; // Error, generic type paramterre
|
||||
~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
var o2 = { ...p2 }; // OK
|
||||
var o3 = { ...t }; // Error, generic type paramter
|
||||
~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
|
||||
var o4 = { ...i }; // Error, index access
|
||||
~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
var o5 = { ...k }; // Error, index
|
||||
~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
|
||||
var o6 = { ...mapped_generic }; // Error, generic mapped object type
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
var o7 = { ...mapped }; // OK, non-generic mapped type
|
||||
|
||||
var o8 = { ...union_generic }; // Error, union with generic type parameter
|
||||
~~~~~~~~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
var o9 = { ...union_primitive }; // Error, union with generic type parameter
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
|
||||
var o10 = { ...intersection_generic }; // Error, intersection with generic type parameter
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
var o11 = { ...intersection_premitive }; // Error, intersection with generic type parameter
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
|
||||
var o12 = { ...num }; // Error
|
||||
~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
var o13 = { ...str }; // Error
|
||||
~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
|
||||
var o14 = { ...u }; // OK
|
||||
var o15 = { ...n }; // OK
|
||||
|
||||
var o16 = { ...a }; // OK
|
||||
|
||||
var o17 = { ...literal_string }; // Error
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
var o18 = { ...literal_number }; // Error
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
|
||||
var o19 = { ...e }; // Error, enum
|
||||
~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
}
|
||||
114
tests/baselines/reference/spreadInvalidArgumentType.js
Normal file
114
tests/baselines/reference/spreadInvalidArgumentType.js
Normal file
@ -0,0 +1,114 @@
|
||||
//// [spreadInvalidArgumentType.ts]
|
||||
enum E { v1, v2 };
|
||||
|
||||
function f<T extends { b: string }>(p1: T, p2: T[]) {
|
||||
var t: T;
|
||||
|
||||
var i: T["b"];
|
||||
var k: keyof T;
|
||||
|
||||
var mapped_generic: {[P in keyof T]: T[P]};
|
||||
var mapped: {[P in "b"]: T[P]};
|
||||
|
||||
var union_generic: T | { a: number };
|
||||
var union_primitive: { a: number } | number;
|
||||
|
||||
var intersection_generic: T & { a: number };
|
||||
var intersection_premitive: { a: number } | string;
|
||||
|
||||
var num: number;
|
||||
var str: number;
|
||||
|
||||
var u: undefined;
|
||||
var n: null;
|
||||
|
||||
var a: any;
|
||||
|
||||
var literal_string: "string";
|
||||
var literal_number: 42;
|
||||
|
||||
var e: E;
|
||||
|
||||
var o1 = { ...p1 }; // Error, generic type paramterre
|
||||
var o2 = { ...p2 }; // OK
|
||||
var o3 = { ...t }; // Error, generic type paramter
|
||||
|
||||
var o4 = { ...i }; // Error, index access
|
||||
var o5 = { ...k }; // Error, index
|
||||
|
||||
var o6 = { ...mapped_generic }; // Error, generic mapped object type
|
||||
var o7 = { ...mapped }; // OK, non-generic mapped type
|
||||
|
||||
var o8 = { ...union_generic }; // Error, union with generic type parameter
|
||||
var o9 = { ...union_primitive }; // Error, union with generic type parameter
|
||||
|
||||
var o10 = { ...intersection_generic }; // Error, intersection with generic type parameter
|
||||
var o11 = { ...intersection_premitive }; // Error, intersection with generic type parameter
|
||||
|
||||
var o12 = { ...num }; // Error
|
||||
var o13 = { ...str }; // Error
|
||||
|
||||
var o14 = { ...u }; // OK
|
||||
var o15 = { ...n }; // OK
|
||||
|
||||
var o16 = { ...a }; // OK
|
||||
|
||||
var o17 = { ...literal_string }; // Error
|
||||
var o18 = { ...literal_number }; // Error
|
||||
|
||||
var o19 = { ...e }; // Error, enum
|
||||
}
|
||||
|
||||
//// [spreadInvalidArgumentType.js]
|
||||
var __assign = (this && this.__assign) || Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
var E;
|
||||
(function (E) {
|
||||
E[E["v1"] = 0] = "v1";
|
||||
E[E["v2"] = 1] = "v2";
|
||||
})(E || (E = {}));
|
||||
;
|
||||
function f(p1, p2) {
|
||||
var t;
|
||||
var i;
|
||||
var k;
|
||||
var mapped_generic;
|
||||
var mapped;
|
||||
var union_generic;
|
||||
var union_primitive;
|
||||
var intersection_generic;
|
||||
var intersection_premitive;
|
||||
var num;
|
||||
var str;
|
||||
var u;
|
||||
var n;
|
||||
var a;
|
||||
var literal_string;
|
||||
var literal_number;
|
||||
var e;
|
||||
var o1 = __assign({}, p1); // Error, generic type paramterre
|
||||
var o2 = __assign({}, p2); // OK
|
||||
var o3 = __assign({}, t); // Error, generic type paramter
|
||||
var o4 = __assign({}, i); // Error, index access
|
||||
var o5 = __assign({}, k); // Error, index
|
||||
var o6 = __assign({}, mapped_generic); // Error, generic mapped object type
|
||||
var o7 = __assign({}, mapped); // OK, non-generic mapped type
|
||||
var o8 = __assign({}, union_generic); // Error, union with generic type parameter
|
||||
var o9 = __assign({}, union_primitive); // Error, union with generic type parameter
|
||||
var o10 = __assign({}, intersection_generic); // Error, intersection with generic type parameter
|
||||
var o11 = __assign({}, intersection_premitive); // Error, intersection with generic type parameter
|
||||
var o12 = __assign({}, num); // Error
|
||||
var o13 = __assign({}, str); // Error
|
||||
var o14 = __assign({}, u); // OK
|
||||
var o15 = __assign({}, n); // OK
|
||||
var o16 = __assign({}, a); // OK
|
||||
var o17 = __assign({}, literal_string); // Error
|
||||
var o18 = __assign({}, literal_number); // Error
|
||||
var o19 = __assign({}, e); // Error, enum
|
||||
}
|
||||
28
tests/baselines/reference/spreadUnion.js
Normal file
28
tests/baselines/reference/spreadUnion.js
Normal file
@ -0,0 +1,28 @@
|
||||
//// [spreadUnion.ts]
|
||||
var union: { a: number } | { b: string };
|
||||
|
||||
var o3: { a: number } | { b: string };
|
||||
var o3 = { ...union };
|
||||
|
||||
var o4: { a: boolean } | { b: string , a: boolean};
|
||||
var o4 = { ...union, a: false };
|
||||
|
||||
var o5: { a: number } | { b: string } | { a: number, b: string };
|
||||
var o5 = { ...union, ...union };
|
||||
|
||||
//// [spreadUnion.js]
|
||||
var __assign = (this && this.__assign) || Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
var union;
|
||||
var o3;
|
||||
var o3 = __assign({}, union);
|
||||
var o4;
|
||||
var o4 = __assign({}, union, { a: false });
|
||||
var o5;
|
||||
var o5 = __assign({}, union, union);
|
||||
38
tests/baselines/reference/spreadUnion.symbols
Normal file
38
tests/baselines/reference/spreadUnion.symbols
Normal file
@ -0,0 +1,38 @@
|
||||
=== tests/cases/compiler/spreadUnion.ts ===
|
||||
var union: { a: number } | { b: string };
|
||||
>union : Symbol(union, Decl(spreadUnion.ts, 0, 3))
|
||||
>a : Symbol(a, Decl(spreadUnion.ts, 0, 12))
|
||||
>b : Symbol(b, Decl(spreadUnion.ts, 0, 28))
|
||||
|
||||
var o3: { a: number } | { b: string };
|
||||
>o3 : Symbol(o3, Decl(spreadUnion.ts, 2, 3), Decl(spreadUnion.ts, 3, 3))
|
||||
>a : Symbol(a, Decl(spreadUnion.ts, 2, 9))
|
||||
>b : Symbol(b, Decl(spreadUnion.ts, 2, 25))
|
||||
|
||||
var o3 = { ...union };
|
||||
>o3 : Symbol(o3, Decl(spreadUnion.ts, 2, 3), Decl(spreadUnion.ts, 3, 3))
|
||||
>union : Symbol(union, Decl(spreadUnion.ts, 0, 3))
|
||||
|
||||
var o4: { a: boolean } | { b: string , a: boolean};
|
||||
>o4 : Symbol(o4, Decl(spreadUnion.ts, 5, 3), Decl(spreadUnion.ts, 6, 3))
|
||||
>a : Symbol(a, Decl(spreadUnion.ts, 5, 9))
|
||||
>b : Symbol(b, Decl(spreadUnion.ts, 5, 26))
|
||||
>a : Symbol(a, Decl(spreadUnion.ts, 5, 38))
|
||||
|
||||
var o4 = { ...union, a: false };
|
||||
>o4 : Symbol(o4, Decl(spreadUnion.ts, 5, 3), Decl(spreadUnion.ts, 6, 3))
|
||||
>union : Symbol(union, Decl(spreadUnion.ts, 0, 3))
|
||||
>a : Symbol(a, Decl(spreadUnion.ts, 6, 21))
|
||||
|
||||
var o5: { a: number } | { b: string } | { a: number, b: string };
|
||||
>o5 : Symbol(o5, Decl(spreadUnion.ts, 8, 3), Decl(spreadUnion.ts, 9, 3))
|
||||
>a : Symbol(a, Decl(spreadUnion.ts, 8, 9))
|
||||
>b : Symbol(b, Decl(spreadUnion.ts, 8, 25))
|
||||
>a : Symbol(a, Decl(spreadUnion.ts, 8, 41))
|
||||
>b : Symbol(b, Decl(spreadUnion.ts, 8, 52))
|
||||
|
||||
var o5 = { ...union, ...union };
|
||||
>o5 : Symbol(o5, Decl(spreadUnion.ts, 8, 3), Decl(spreadUnion.ts, 9, 3))
|
||||
>union : Symbol(union, Decl(spreadUnion.ts, 0, 3))
|
||||
>union : Symbol(union, Decl(spreadUnion.ts, 0, 3))
|
||||
|
||||
42
tests/baselines/reference/spreadUnion.types
Normal file
42
tests/baselines/reference/spreadUnion.types
Normal file
@ -0,0 +1,42 @@
|
||||
=== tests/cases/compiler/spreadUnion.ts ===
|
||||
var union: { a: number } | { b: string };
|
||||
>union : { a: number; } | { b: string; }
|
||||
>a : number
|
||||
>b : string
|
||||
|
||||
var o3: { a: number } | { b: string };
|
||||
>o3 : { a: number; } | { b: string; }
|
||||
>a : number
|
||||
>b : string
|
||||
|
||||
var o3 = { ...union };
|
||||
>o3 : { a: number; } | { b: string; }
|
||||
>{ ...union } : { a: number; } | { b: string; }
|
||||
>union : { a: number; } | { b: string; }
|
||||
|
||||
var o4: { a: boolean } | { b: string , a: boolean};
|
||||
>o4 : { a: boolean; } | { b: string; a: boolean; }
|
||||
>a : boolean
|
||||
>b : string
|
||||
>a : boolean
|
||||
|
||||
var o4 = { ...union, a: false };
|
||||
>o4 : { a: boolean; } | { b: string; a: boolean; }
|
||||
>{ ...union, a: false } : { a: boolean; } | { a: boolean; b: string; }
|
||||
>union : { a: number; } | { b: string; }
|
||||
>a : boolean
|
||||
>false : false
|
||||
|
||||
var o5: { a: number } | { b: string } | { a: number, b: string };
|
||||
>o5 : { a: number; } | { b: string; } | { a: number; b: string; }
|
||||
>a : number
|
||||
>b : string
|
||||
>a : number
|
||||
>b : string
|
||||
|
||||
var o5 = { ...union, ...union };
|
||||
>o5 : { a: number; } | { b: string; } | { a: number; b: string; }
|
||||
>{ ...union, ...union } : { a: number; } | { b: string; a: number; } | { a: number; b: string; } | { b: string; }
|
||||
>union : { a: number; } | { b: string; }
|
||||
>union : { a: number; } | { b: string; }
|
||||
|
||||
49
tests/baselines/reference/spreadUnion2.js
Normal file
49
tests/baselines/reference/spreadUnion2.js
Normal file
@ -0,0 +1,49 @@
|
||||
//// [spreadUnion2.ts]
|
||||
|
||||
declare const undefinedUnion: { a: number } | undefined;
|
||||
declare const nullUnion: { b: number } | null;
|
||||
declare const nullAndUndefinedUnion: null | undefined;
|
||||
|
||||
var o1: { a: number };
|
||||
var o1 = { ...undefinedUnion };
|
||||
|
||||
var o2: { b: number };
|
||||
var o2 = { ...nullUnion };
|
||||
|
||||
var o3: { a: number, b: number };
|
||||
var o3 = { ...undefinedUnion, ...nullUnion };
|
||||
var o3 = { ...nullUnion, ...undefinedUnion };
|
||||
|
||||
var o4: { a: number };
|
||||
var o4 = { ...undefinedUnion, ...undefinedUnion };
|
||||
|
||||
var o5: { b: number };
|
||||
var o5 = { ...nullUnion, ...nullUnion };
|
||||
|
||||
var o6: { };
|
||||
var o6 = { ...nullAndUndefinedUnion, ...nullAndUndefinedUnion };
|
||||
var o6 = { ...nullAndUndefinedUnion };
|
||||
|
||||
//// [spreadUnion2.js]
|
||||
var __assign = (this && this.__assign) || Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
var o1;
|
||||
var o1 = __assign({}, undefinedUnion);
|
||||
var o2;
|
||||
var o2 = __assign({}, nullUnion);
|
||||
var o3;
|
||||
var o3 = __assign({}, undefinedUnion, nullUnion);
|
||||
var o3 = __assign({}, nullUnion, undefinedUnion);
|
||||
var o4;
|
||||
var o4 = __assign({}, undefinedUnion, undefinedUnion);
|
||||
var o5;
|
||||
var o5 = __assign({}, nullUnion, nullUnion);
|
||||
var o6;
|
||||
var o6 = __assign({}, nullAndUndefinedUnion, nullAndUndefinedUnion);
|
||||
var o6 = __assign({}, nullAndUndefinedUnion);
|
||||
74
tests/baselines/reference/spreadUnion2.symbols
Normal file
74
tests/baselines/reference/spreadUnion2.symbols
Normal file
@ -0,0 +1,74 @@
|
||||
=== tests/cases/compiler/spreadUnion2.ts ===
|
||||
|
||||
declare const undefinedUnion: { a: number } | undefined;
|
||||
>undefinedUnion : Symbol(undefinedUnion, Decl(spreadUnion2.ts, 1, 13))
|
||||
>a : Symbol(a, Decl(spreadUnion2.ts, 1, 31))
|
||||
|
||||
declare const nullUnion: { b: number } | null;
|
||||
>nullUnion : Symbol(nullUnion, Decl(spreadUnion2.ts, 2, 13))
|
||||
>b : Symbol(b, Decl(spreadUnion2.ts, 2, 26))
|
||||
|
||||
declare const nullAndUndefinedUnion: null | undefined;
|
||||
>nullAndUndefinedUnion : Symbol(nullAndUndefinedUnion, Decl(spreadUnion2.ts, 3, 13))
|
||||
|
||||
var o1: { a: number };
|
||||
>o1 : Symbol(o1, Decl(spreadUnion2.ts, 5, 3), Decl(spreadUnion2.ts, 6, 3))
|
||||
>a : Symbol(a, Decl(spreadUnion2.ts, 5, 9))
|
||||
|
||||
var o1 = { ...undefinedUnion };
|
||||
>o1 : Symbol(o1, Decl(spreadUnion2.ts, 5, 3), Decl(spreadUnion2.ts, 6, 3))
|
||||
>undefinedUnion : Symbol(undefinedUnion, Decl(spreadUnion2.ts, 1, 13))
|
||||
|
||||
var o2: { b: number };
|
||||
>o2 : Symbol(o2, Decl(spreadUnion2.ts, 8, 3), Decl(spreadUnion2.ts, 9, 3))
|
||||
>b : Symbol(b, Decl(spreadUnion2.ts, 8, 9))
|
||||
|
||||
var o2 = { ...nullUnion };
|
||||
>o2 : Symbol(o2, Decl(spreadUnion2.ts, 8, 3), Decl(spreadUnion2.ts, 9, 3))
|
||||
>nullUnion : Symbol(nullUnion, Decl(spreadUnion2.ts, 2, 13))
|
||||
|
||||
var o3: { a: number, b: number };
|
||||
>o3 : Symbol(o3, Decl(spreadUnion2.ts, 11, 3), Decl(spreadUnion2.ts, 12, 3), Decl(spreadUnion2.ts, 13, 3))
|
||||
>a : Symbol(a, Decl(spreadUnion2.ts, 11, 9))
|
||||
>b : Symbol(b, Decl(spreadUnion2.ts, 11, 20))
|
||||
|
||||
var o3 = { ...undefinedUnion, ...nullUnion };
|
||||
>o3 : Symbol(o3, Decl(spreadUnion2.ts, 11, 3), Decl(spreadUnion2.ts, 12, 3), Decl(spreadUnion2.ts, 13, 3))
|
||||
>undefinedUnion : Symbol(undefinedUnion, Decl(spreadUnion2.ts, 1, 13))
|
||||
>nullUnion : Symbol(nullUnion, Decl(spreadUnion2.ts, 2, 13))
|
||||
|
||||
var o3 = { ...nullUnion, ...undefinedUnion };
|
||||
>o3 : Symbol(o3, Decl(spreadUnion2.ts, 11, 3), Decl(spreadUnion2.ts, 12, 3), Decl(spreadUnion2.ts, 13, 3))
|
||||
>nullUnion : Symbol(nullUnion, Decl(spreadUnion2.ts, 2, 13))
|
||||
>undefinedUnion : Symbol(undefinedUnion, Decl(spreadUnion2.ts, 1, 13))
|
||||
|
||||
var o4: { a: number };
|
||||
>o4 : Symbol(o4, Decl(spreadUnion2.ts, 15, 3), Decl(spreadUnion2.ts, 16, 3))
|
||||
>a : Symbol(a, Decl(spreadUnion2.ts, 15, 9))
|
||||
|
||||
var o4 = { ...undefinedUnion, ...undefinedUnion };
|
||||
>o4 : Symbol(o4, Decl(spreadUnion2.ts, 15, 3), Decl(spreadUnion2.ts, 16, 3))
|
||||
>undefinedUnion : Symbol(undefinedUnion, Decl(spreadUnion2.ts, 1, 13))
|
||||
>undefinedUnion : Symbol(undefinedUnion, Decl(spreadUnion2.ts, 1, 13))
|
||||
|
||||
var o5: { b: number };
|
||||
>o5 : Symbol(o5, Decl(spreadUnion2.ts, 18, 3), Decl(spreadUnion2.ts, 19, 3))
|
||||
>b : Symbol(b, Decl(spreadUnion2.ts, 18, 9))
|
||||
|
||||
var o5 = { ...nullUnion, ...nullUnion };
|
||||
>o5 : Symbol(o5, Decl(spreadUnion2.ts, 18, 3), Decl(spreadUnion2.ts, 19, 3))
|
||||
>nullUnion : Symbol(nullUnion, Decl(spreadUnion2.ts, 2, 13))
|
||||
>nullUnion : Symbol(nullUnion, Decl(spreadUnion2.ts, 2, 13))
|
||||
|
||||
var o6: { };
|
||||
>o6 : Symbol(o6, Decl(spreadUnion2.ts, 21, 3), Decl(spreadUnion2.ts, 22, 3), Decl(spreadUnion2.ts, 23, 3))
|
||||
|
||||
var o6 = { ...nullAndUndefinedUnion, ...nullAndUndefinedUnion };
|
||||
>o6 : Symbol(o6, Decl(spreadUnion2.ts, 21, 3), Decl(spreadUnion2.ts, 22, 3), Decl(spreadUnion2.ts, 23, 3))
|
||||
>nullAndUndefinedUnion : Symbol(nullAndUndefinedUnion, Decl(spreadUnion2.ts, 3, 13))
|
||||
>nullAndUndefinedUnion : Symbol(nullAndUndefinedUnion, Decl(spreadUnion2.ts, 3, 13))
|
||||
|
||||
var o6 = { ...nullAndUndefinedUnion };
|
||||
>o6 : Symbol(o6, Decl(spreadUnion2.ts, 21, 3), Decl(spreadUnion2.ts, 22, 3), Decl(spreadUnion2.ts, 23, 3))
|
||||
>nullAndUndefinedUnion : Symbol(nullAndUndefinedUnion, Decl(spreadUnion2.ts, 3, 13))
|
||||
|
||||
84
tests/baselines/reference/spreadUnion2.types
Normal file
84
tests/baselines/reference/spreadUnion2.types
Normal file
@ -0,0 +1,84 @@
|
||||
=== tests/cases/compiler/spreadUnion2.ts ===
|
||||
|
||||
declare const undefinedUnion: { a: number } | undefined;
|
||||
>undefinedUnion : { a: number; } | undefined
|
||||
>a : number
|
||||
|
||||
declare const nullUnion: { b: number } | null;
|
||||
>nullUnion : { b: number; } | null
|
||||
>b : number
|
||||
>null : null
|
||||
|
||||
declare const nullAndUndefinedUnion: null | undefined;
|
||||
>nullAndUndefinedUnion : null | undefined
|
||||
>null : null
|
||||
|
||||
var o1: { a: number };
|
||||
>o1 : { a: number; }
|
||||
>a : number
|
||||
|
||||
var o1 = { ...undefinedUnion };
|
||||
>o1 : { a: number; }
|
||||
>{ ...undefinedUnion } : { a: number; }
|
||||
>undefinedUnion : { a: number; } | undefined
|
||||
|
||||
var o2: { b: number };
|
||||
>o2 : { b: number; }
|
||||
>b : number
|
||||
|
||||
var o2 = { ...nullUnion };
|
||||
>o2 : { b: number; }
|
||||
>{ ...nullUnion } : { b: number; }
|
||||
>nullUnion : { b: number; } | null
|
||||
|
||||
var o3: { a: number, b: number };
|
||||
>o3 : { a: number; b: number; }
|
||||
>a : number
|
||||
>b : number
|
||||
|
||||
var o3 = { ...undefinedUnion, ...nullUnion };
|
||||
>o3 : { a: number; b: number; }
|
||||
>{ ...undefinedUnion, ...nullUnion } : { b: number; a: number; }
|
||||
>undefinedUnion : { a: number; } | undefined
|
||||
>nullUnion : { b: number; } | null
|
||||
|
||||
var o3 = { ...nullUnion, ...undefinedUnion };
|
||||
>o3 : { a: number; b: number; }
|
||||
>{ ...nullUnion, ...undefinedUnion } : { a: number; b: number; }
|
||||
>nullUnion : { b: number; } | null
|
||||
>undefinedUnion : { a: number; } | undefined
|
||||
|
||||
var o4: { a: number };
|
||||
>o4 : { a: number; }
|
||||
>a : number
|
||||
|
||||
var o4 = { ...undefinedUnion, ...undefinedUnion };
|
||||
>o4 : { a: number; }
|
||||
>{ ...undefinedUnion, ...undefinedUnion } : { a: number; }
|
||||
>undefinedUnion : { a: number; } | undefined
|
||||
>undefinedUnion : { a: number; } | undefined
|
||||
|
||||
var o5: { b: number };
|
||||
>o5 : { b: number; }
|
||||
>b : number
|
||||
|
||||
var o5 = { ...nullUnion, ...nullUnion };
|
||||
>o5 : { b: number; }
|
||||
>{ ...nullUnion, ...nullUnion } : { b: number; }
|
||||
>nullUnion : { b: number; } | null
|
||||
>nullUnion : { b: number; } | null
|
||||
|
||||
var o6: { };
|
||||
>o6 : {}
|
||||
|
||||
var o6 = { ...nullAndUndefinedUnion, ...nullAndUndefinedUnion };
|
||||
>o6 : {}
|
||||
>{ ...nullAndUndefinedUnion, ...nullAndUndefinedUnion } : {}
|
||||
>nullAndUndefinedUnion : null | undefined
|
||||
>nullAndUndefinedUnion : null | undefined
|
||||
|
||||
var o6 = { ...nullAndUndefinedUnion };
|
||||
>o6 : {}
|
||||
>{ ...nullAndUndefinedUnion } : {}
|
||||
>nullAndUndefinedUnion : null | undefined
|
||||
|
||||
4
tests/cases/compiler/restIntersection.ts
Normal file
4
tests/cases/compiler/restIntersection.ts
Normal file
@ -0,0 +1,4 @@
|
||||
var intersection: { x: number, y: number } & { w: string, z: string };
|
||||
|
||||
var rest1: { y: number, w: string, z: string };
|
||||
var {x, ...rest1 } = intersection;
|
||||
59
tests/cases/compiler/restInvalidArgumentType.ts
Normal file
59
tests/cases/compiler/restInvalidArgumentType.ts
Normal file
@ -0,0 +1,59 @@
|
||||
enum E { v1, v2 };
|
||||
|
||||
function f<T extends { b: string }>(p1: T, p2: T[]) {
|
||||
var t: T;
|
||||
|
||||
var i: T["b"];
|
||||
var k: keyof T;
|
||||
|
||||
var mapped_generic: {[P in keyof T]: T[P]};
|
||||
var mapped: {[P in "b"]: T[P]};
|
||||
|
||||
var union_generic: T | { a: number };
|
||||
var union_primitive: { a: number } | number;
|
||||
|
||||
var intersection_generic: T & { a: number };
|
||||
var intersection_premitive: { a: number } | string;
|
||||
|
||||
var num: number;
|
||||
var str: number;
|
||||
|
||||
var u: undefined;
|
||||
var n: null;
|
||||
|
||||
var a: any;
|
||||
|
||||
var literal_string: "string";
|
||||
var literal_number: 42;
|
||||
|
||||
var e: E;
|
||||
|
||||
var {...r1} = p1; // Error, generic type paramterre
|
||||
var {...r2} = p2; // OK
|
||||
var {...r3} = t; // Error, generic type paramter
|
||||
|
||||
var {...r4} = i; // Error, index access
|
||||
var {...r5} = k; // Error, index
|
||||
|
||||
var {...r6} = mapped_generic; // Error, generic mapped object type
|
||||
var {...r7} = mapped; // OK, non-generic mapped type
|
||||
|
||||
var {...r8} = union_generic; // Error, union with generic type parameter
|
||||
var {...r9} = union_primitive; // Error, union with generic type parameter
|
||||
|
||||
var {...r10} = intersection_generic; // Error, intersection with generic type parameter
|
||||
var {...r11} = intersection_premitive; // Error, intersection with generic type parameter
|
||||
|
||||
var {...r12} = num; // Error
|
||||
var {...r13} = str; // Error
|
||||
|
||||
var {...r14} = u; // OK
|
||||
var {...r15} = n; // OK
|
||||
|
||||
var {...r16} = a; // OK
|
||||
|
||||
var {...r17} = literal_string; // Error
|
||||
var {...r18} = literal_number; // Error
|
||||
|
||||
var {...r19} = e; // Error, enum
|
||||
}
|
||||
14
tests/cases/compiler/restUnion.ts
Normal file
14
tests/cases/compiler/restUnion.ts
Normal file
@ -0,0 +1,14 @@
|
||||
var union: { a: number, c: boolean } | { a: string, b: string };
|
||||
|
||||
var rest1: { c: boolean } | { b: string };
|
||||
var {a, ...rest1 } = union;
|
||||
|
||||
|
||||
var undefinedUnion: { n: number } | undefined;
|
||||
var rest2: {};
|
||||
var {n, ...rest2 } = undefinedUnion;
|
||||
|
||||
|
||||
var nullUnion: { n: number } | null;
|
||||
var rest3: {};
|
||||
var {n, ...rest3 } = nullUnion;
|
||||
19
tests/cases/compiler/restUnion2.ts
Normal file
19
tests/cases/compiler/restUnion2.ts
Normal file
@ -0,0 +1,19 @@
|
||||
// @strictNullChecks: true
|
||||
|
||||
declare const undefinedUnion: { n: number } | undefined;
|
||||
var rest2: { n: number };
|
||||
var {...rest2 } = undefinedUnion;
|
||||
|
||||
|
||||
declare const nullUnion: { n: number } | null;
|
||||
var rest3: { n: number };
|
||||
var {...rest3 } = nullUnion;
|
||||
|
||||
|
||||
declare const nullAndUndefinedUnion: null | undefined;
|
||||
var rest4: { };
|
||||
var {...rest4 } = nullAndUndefinedUnion;
|
||||
|
||||
declare const unionWithIntersection: ({ n: number } & { s: string }) & undefined | null;
|
||||
var rest5: { n: number, s: string };
|
||||
var {...rest5 } = unionWithIntersection;
|
||||
7
tests/cases/compiler/spreadIntersection.ts
Normal file
7
tests/cases/compiler/spreadIntersection.ts
Normal file
@ -0,0 +1,7 @@
|
||||
var intersection: { a: number } & { b: string };
|
||||
|
||||
var o1: { a: number, b: string };
|
||||
var o1 = { ...intersection };
|
||||
|
||||
var o2: { a: number, b: string, c: boolean };
|
||||
var o2 = { ...intersection, c: false };
|
||||
59
tests/cases/compiler/spreadInvalidArgumentType.ts
Normal file
59
tests/cases/compiler/spreadInvalidArgumentType.ts
Normal file
@ -0,0 +1,59 @@
|
||||
enum E { v1, v2 };
|
||||
|
||||
function f<T extends { b: string }>(p1: T, p2: T[]) {
|
||||
var t: T;
|
||||
|
||||
var i: T["b"];
|
||||
var k: keyof T;
|
||||
|
||||
var mapped_generic: {[P in keyof T]: T[P]};
|
||||
var mapped: {[P in "b"]: T[P]};
|
||||
|
||||
var union_generic: T | { a: number };
|
||||
var union_primitive: { a: number } | number;
|
||||
|
||||
var intersection_generic: T & { a: number };
|
||||
var intersection_premitive: { a: number } | string;
|
||||
|
||||
var num: number;
|
||||
var str: number;
|
||||
|
||||
var u: undefined;
|
||||
var n: null;
|
||||
|
||||
var a: any;
|
||||
|
||||
var literal_string: "string";
|
||||
var literal_number: 42;
|
||||
|
||||
var e: E;
|
||||
|
||||
var o1 = { ...p1 }; // Error, generic type paramterre
|
||||
var o2 = { ...p2 }; // OK
|
||||
var o3 = { ...t }; // Error, generic type paramter
|
||||
|
||||
var o4 = { ...i }; // Error, index access
|
||||
var o5 = { ...k }; // Error, index
|
||||
|
||||
var o6 = { ...mapped_generic }; // Error, generic mapped object type
|
||||
var o7 = { ...mapped }; // OK, non-generic mapped type
|
||||
|
||||
var o8 = { ...union_generic }; // Error, union with generic type parameter
|
||||
var o9 = { ...union_primitive }; // Error, union with generic type parameter
|
||||
|
||||
var o10 = { ...intersection_generic }; // Error, intersection with generic type parameter
|
||||
var o11 = { ...intersection_premitive }; // Error, intersection with generic type parameter
|
||||
|
||||
var o12 = { ...num }; // Error
|
||||
var o13 = { ...str }; // Error
|
||||
|
||||
var o14 = { ...u }; // OK
|
||||
var o15 = { ...n }; // OK
|
||||
|
||||
var o16 = { ...a }; // OK
|
||||
|
||||
var o17 = { ...literal_string }; // Error
|
||||
var o18 = { ...literal_number }; // Error
|
||||
|
||||
var o19 = { ...e }; // Error, enum
|
||||
}
|
||||
10
tests/cases/compiler/spreadUnion.ts
Normal file
10
tests/cases/compiler/spreadUnion.ts
Normal file
@ -0,0 +1,10 @@
|
||||
var union: { a: number } | { b: string };
|
||||
|
||||
var o3: { a: number } | { b: string };
|
||||
var o3 = { ...union };
|
||||
|
||||
var o4: { a: boolean } | { b: string , a: boolean};
|
||||
var o4 = { ...union, a: false };
|
||||
|
||||
var o5: { a: number } | { b: string } | { a: number, b: string };
|
||||
var o5 = { ...union, ...union };
|
||||
25
tests/cases/compiler/spreadUnion2.ts
Normal file
25
tests/cases/compiler/spreadUnion2.ts
Normal file
@ -0,0 +1,25 @@
|
||||
// @strictNullChecks: true
|
||||
|
||||
declare const undefinedUnion: { a: number } | undefined;
|
||||
declare const nullUnion: { b: number } | null;
|
||||
declare const nullAndUndefinedUnion: null | undefined;
|
||||
|
||||
var o1: { a: number };
|
||||
var o1 = { ...undefinedUnion };
|
||||
|
||||
var o2: { b: number };
|
||||
var o2 = { ...nullUnion };
|
||||
|
||||
var o3: { a: number, b: number };
|
||||
var o3 = { ...undefinedUnion, ...nullUnion };
|
||||
var o3 = { ...nullUnion, ...undefinedUnion };
|
||||
|
||||
var o4: { a: number };
|
||||
var o4 = { ...undefinedUnion, ...undefinedUnion };
|
||||
|
||||
var o5: { b: number };
|
||||
var o5 = { ...nullUnion, ...nullUnion };
|
||||
|
||||
var o6: { };
|
||||
var o6 = { ...nullAndUndefinedUnion, ...nullAndUndefinedUnion };
|
||||
var o6 = { ...nullAndUndefinedUnion };
|
||||
@ -29,9 +29,7 @@ spread = b; // error, missing 's'
|
||||
let duplicated = { b: 'bad', ...o, b: 'bad', ...o2, b: 'bad' }
|
||||
let duplicatedSpread = { ...o, ...o }
|
||||
|
||||
// null, undefined and primitives are not allowed
|
||||
let spreadNull = { ...null };
|
||||
let spreadUndefind = { ...undefined };
|
||||
// primitives are not allowed
|
||||
let spreadNum = { ...12 };
|
||||
let spreadSum = { ...1 + 1 };
|
||||
spreadSum.toFixed(); // error, no methods from number
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user