diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 549cdbc55144a..6348d12781f5b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9526,44 +9526,13 @@ namespace ts { return false; } - // Return true if the given intersection type contains - // more than one unit type or, - // an object type and a nullable type (null or undefined), or - // a string-like type and a type known to be non-string-like, or - // a number-like type and a type known to be non-number-like, or - // a symbol-like type and a type known to be non-symbol-like, or - // a void-like type and a type known to be non-void-like, or - // a non-primitive type and a type known to be primitive. - function isEmptyIntersectionType(type: IntersectionType) { - let combined: TypeFlags = 0; - for (const t of type.types) { - if (t.flags & TypeFlags.Unit && combined & TypeFlags.Unit) { - return true; - } - combined |= t.flags; - if (combined & TypeFlags.Nullable && combined & (TypeFlags.Object | TypeFlags.NonPrimitive) || - combined & TypeFlags.NonPrimitive && combined & (TypeFlags.DisjointDomains & ~TypeFlags.NonPrimitive) || - combined & TypeFlags.StringLike && combined & (TypeFlags.DisjointDomains & ~TypeFlags.StringLike) || - combined & TypeFlags.NumberLike && combined & (TypeFlags.DisjointDomains & ~TypeFlags.NumberLike) || - combined & TypeFlags.BigIntLike && combined & (TypeFlags.DisjointDomains & ~TypeFlags.BigIntLike) || - combined & TypeFlags.ESSymbolLike && combined & (TypeFlags.DisjointDomains & ~TypeFlags.ESSymbolLike) || - combined & TypeFlags.VoidLike && combined & (TypeFlags.DisjointDomains & ~TypeFlags.VoidLike)) { - return true; - } - } - return false; - } - function addTypeToUnion(typeSet: Type[], includes: TypeFlags, type: Type) { const flags = type.flags; if (flags & TypeFlags.Union) { return addTypesToUnion(typeSet, includes, (type).types); } - // We ignore 'never' types in unions. Likewise, we ignore intersections of unit types as they are - // another form of 'never' (in that they have an empty value domain). We could in theory turn - // intersections of unit types into 'never' upon construction, but deferring the reduction makes it - // easier to reason about their origin. - if (!(flags & TypeFlags.Never || flags & TypeFlags.Intersection && isEmptyIntersectionType(type))) { + // We ignore 'never' types in unions + if (!(flags & TypeFlags.Never)) { includes |= flags & TypeFlags.IncludesMask; if (flags & TypeFlags.StructuredOrInstantiable) includes |= TypeFlags.IncludesStructuredOrInstantiable; if (type === wildcardType) includes |= TypeFlags.IncludesWildcard; @@ -9787,13 +9756,18 @@ namespace ts { } } else { - includes |= flags & TypeFlags.IncludesMask; if (flags & TypeFlags.AnyOrUnknown) { if (type === wildcardType) includes |= TypeFlags.IncludesWildcard; } else if ((strictNullChecks || !(flags & TypeFlags.Nullable)) && !contains(typeSet, type)) { + if (type.flags & TypeFlags.Unit && includes & TypeFlags.Unit) { + // We have seen two distinct unit types which means we should reduce to an + // empty intersection. Adding TypeFlags.NonPrimitive causes that to happen. + includes |= TypeFlags.NonPrimitive; + } typeSet.push(type); } + includes |= flags & TypeFlags.IncludesMask; } return includes; } @@ -9909,7 +9883,23 @@ namespace ts { function getIntersectionType(types: readonly Type[], aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[]): Type { const typeSet: Type[] = []; const includes = addTypesToIntersection(typeSet, 0, types); - if (includes & TypeFlags.Never) { + // An intersection type is considered empty if it contains + // the type never, or + // more than one unit type or, + // an object type and a nullable type (null or undefined), or + // a string-like type and a type known to be non-string-like, or + // a number-like type and a type known to be non-number-like, or + // a symbol-like type and a type known to be non-symbol-like, or + // a void-like type and a type known to be non-void-like, or + // a non-primitive type and a type known to be primitive. + if (includes & TypeFlags.Never || + strictNullChecks && includes & TypeFlags.Nullable && includes & (TypeFlags.Object | TypeFlags.NonPrimitive | TypeFlags.IncludesEmptyObject) || + includes & TypeFlags.NonPrimitive && includes & (TypeFlags.DisjointDomains & ~TypeFlags.NonPrimitive) || + includes & TypeFlags.StringLike && includes & (TypeFlags.DisjointDomains & ~TypeFlags.StringLike) || + includes & TypeFlags.NumberLike && includes & (TypeFlags.DisjointDomains & ~TypeFlags.NumberLike) || + includes & TypeFlags.BigIntLike && includes & (TypeFlags.DisjointDomains & ~TypeFlags.BigIntLike) || + includes & TypeFlags.ESSymbolLike && includes & (TypeFlags.DisjointDomains & ~TypeFlags.ESSymbolLike) || + includes & TypeFlags.VoidLike && includes & (TypeFlags.DisjointDomains & ~TypeFlags.VoidLike)) { return neverType; } if (includes & TypeFlags.Any) { @@ -14633,7 +14623,7 @@ namespace ts { } function createSymbolWithType(source: Symbol, type: Type | undefined) { - const symbol = createSymbol(source.flags, source.escapedName); + const symbol = createSymbol(source.flags, source.escapedName, getCheckFlags(source) & CheckFlags.Readonly); symbol.declarations = source.declarations; symbol.parent = source.parent; symbol.type = type; @@ -19093,8 +19083,8 @@ namespace ts { } function checkSpreadExpression(node: SpreadElement, checkMode?: CheckMode): Type { - if (languageVersion < ScriptTarget.ES2015 && compilerOptions.downlevelIteration) { - checkExternalEmitHelpers(node, ExternalEmitHelpers.SpreadIncludes); + if (languageVersion < ScriptTarget.ES2015) { + checkExternalEmitHelpers(node, compilerOptions.downlevelIteration ? ExternalEmitHelpers.SpreadIncludes : ExternalEmitHelpers.SpreadArrays); } const arrayOrIterableType = checkExpression(node.expression, checkMode); @@ -31127,6 +31117,7 @@ namespace ts { case ExternalEmitHelpers.Values: return "__values"; case ExternalEmitHelpers.Read: return "__read"; case ExternalEmitHelpers.Spread: return "__spread"; + case ExternalEmitHelpers.SpreadArrays: return "__spreadArrays"; case ExternalEmitHelpers.Await: return "__await"; case ExternalEmitHelpers.AsyncGenerator: return "__asyncGenerator"; case ExternalEmitHelpers.AsyncDelegator: return "__asyncDelegator"; diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 3f5f8f9f02956..4598872023fd5 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -2658,6 +2658,7 @@ namespace ts { valuesHelper, readHelper, spreadHelper, + spreadArraysHelper, restHelper, decorateHelper, metadataHelper, @@ -3693,6 +3694,31 @@ namespace ts { // eslint-disable-line no-redeclare ); } + export const spreadArraysHelper: UnscopedEmitHelper = { + name: "typescript:spreadArrays", + scoped: false, + text: ` + var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; + };` + }; + + export function createSpreadArraysHelper(context: TransformationContext, argumentList: ReadonlyArray, location?: TextRange) { + context.requestEmitHelper(spreadArraysHelper); + return setTextRange( + createCall( + getHelperName("__spreadArrays"), + /*typeArguments*/ undefined, + argumentList + ), + location + ); + } + // Utilities export function createForOfBindingStatement(node: ForInitializer, boundValue: Expression): Statement { diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 218683c077e91..79b8b759d4d87 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -3819,8 +3819,11 @@ namespace ts { // [source] // [a, ...b, c] // + // [output (downlevelIteration)] + // __spread([a], b, [c]) + // // [output] - // [a].concat(b, [c]) + // __spreadArrays([a], b, [c]) // Map spans of spread expressions into their expressions and spans of other // expressions into an array literal. @@ -3834,10 +3837,7 @@ namespace ts { if (compilerOptions.downlevelIteration) { if (segments.length === 1) { const firstSegment = segments[0]; - if (isCallExpression(firstSegment) - && isIdentifier(firstSegment.expression) - && (getEmitFlags(firstSegment.expression) & EmitFlags.HelperName) - && firstSegment.expression.escapedText === "___spread") { + if (isCallToHelper(firstSegment, "___spread" as __String)) { return segments[0]; } } @@ -3846,17 +3846,33 @@ namespace ts { } else { if (segments.length === 1) { - const firstElement = elements[0]; - return needsUniqueCopy && isSpreadElement(firstElement) && firstElement.expression.kind !== SyntaxKind.ArrayLiteralExpression - ? createArraySlice(segments[0]) - : segments[0]; + const firstSegment = segments[0]; + if (!needsUniqueCopy + || isPackedArrayLiteral(firstSegment) + || isCallToHelper(firstSegment, "___spreadArrays" as __String)) { + return segments[0]; + } } - // Rewrite using the pattern .concat(, , ...) - return createArrayConcat(segments.shift()!, segments); + return createSpreadArraysHelper(context, segments); } } + function isPackedElement(node: Expression) { + return !isOmittedExpression(node); + } + + function isPackedArrayLiteral(node: Expression) { + return isArrayLiteralExpression(node) && every(node.elements, isPackedElement); + } + + function isCallToHelper(firstSegment: Expression, helperName: __String) { + return isCallExpression(firstSegment) + && isIdentifier(firstSegment.expression) + && (getEmitFlags(firstSegment.expression) & EmitFlags.HelperName) + && firstSegment.expression.escapedText === helperName; + } + function partitionSpread(node: Expression) { return isSpreadElement(node) ? visitSpanOfSpreads diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d977e81a96337..59032fdec8404 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3984,7 +3984,7 @@ namespace ts { NotPrimitiveUnion = Any | Unknown | Enum | Void | Never | StructuredOrInstantiable, // The following flags are aggregated during union and intersection type construction /* @internal */ - IncludesMask = Any | Unknown | Primitive | Never | Object | Union, + IncludesMask = Any | Unknown | Primitive | Never | Object | Union | NonPrimitive, // The following flags are used for different purposes during union and intersection type construction /* @internal */ IncludesStructuredOrInstantiable = TypeParameter, @@ -5340,12 +5340,13 @@ namespace ts { Values = 1 << 8, // __values (used by ES2015 for..of and yield* transformations) Read = 1 << 9, // __read (used by ES2015 iterator destructuring transformation) Spread = 1 << 10, // __spread (used by ES2015 array spread and argument list spread transformations) - Await = 1 << 11, // __await (used by ES2017 async generator transformation) - AsyncGenerator = 1 << 12, // __asyncGenerator (used by ES2017 async generator transformation) - AsyncDelegator = 1 << 13, // __asyncDelegator (used by ES2017 async generator yield* transformation) - AsyncValues = 1 << 14, // __asyncValues (used by ES2017 for..await..of transformation) - ExportStar = 1 << 15, // __exportStar (used by CommonJS/AMD/UMD module transformation) - MakeTemplateObject = 1 << 16, // __makeTemplateObject (used for constructing template string array objects) + SpreadArrays = 1 << 11, // __spreadArrays (used by ES2015 array spread and argument list spread transformations) + Await = 1 << 12, // __await (used by ES2017 async generator transformation) + AsyncGenerator = 1 << 13, // __asyncGenerator (used by ES2017 async generator transformation) + AsyncDelegator = 1 << 14, // __asyncDelegator (used by ES2017 async generator yield* transformation) + AsyncValues = 1 << 15, // __asyncValues (used by ES2017 for..await..of transformation) + ExportStar = 1 << 16, // __exportStar (used by CommonJS/AMD/UMD module transformation) + MakeTemplateObject = 1 << 17, // __makeTemplateObject (used for constructing template string array objects) FirstEmitHelper = Extends, LastEmitHelper = MakeTemplateObject, diff --git a/tests/baselines/reference/argumentExpressionContextualTyping.js b/tests/baselines/reference/argumentExpressionContextualTyping.js index d3383612327e5..14efadcab7585 100644 --- a/tests/baselines/reference/argumentExpressionContextualTyping.js +++ b/tests/baselines/reference/argumentExpressionContextualTyping.js @@ -19,6 +19,13 @@ baz(["string", 1, true, ...array]); // Error foo(o); // Error because x has an array type namely (string|number)[] //// [argumentExpressionContextualTyping.js] +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; // In a typed function call, argument expressions are contextually typed by their corresponding parameter types. function foo(_a) { var _b = _a.x, a = _b[0], b = _b[1], _c = _a.y, c = _c.c, d = _c.d, e = _c.e; @@ -36,5 +43,5 @@ var tuple = ["string", 1, true]; baz(tuple); baz(["string", 1, true]); baz(array); // Error -baz(["string", 1, true].concat(array)); // Error +baz(__spreadArrays(["string", 1, true], array)); // Error foo(o); // Error because x has an array type namely (string|number)[] diff --git a/tests/baselines/reference/arrayLiteralExpressionContextualTyping.js b/tests/baselines/reference/arrayLiteralExpressionContextualTyping.js index 852a632f3611c..9061b1a9d4e84 100644 --- a/tests/baselines/reference/arrayLiteralExpressionContextualTyping.js +++ b/tests/baselines/reference/arrayLiteralExpressionContextualTyping.js @@ -16,6 +16,13 @@ var spr2:[number, number, number] = [1, 2, 3, ...tup]; // Error //// [arrayLiteralExpressionContextualTyping.js] +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; // In a contextually typed array literal expression containing no spread elements, an element expression at index N is contextually typed by // the type of the property with the numeric name N in the contextual type, if any, or otherwise // the numeric index type of the contextual type, if any. @@ -26,6 +33,6 @@ var tup1 = [1, 2, 3, "string"]; var tup2 = [1, 2, 3, "string"]; // Error // In a contextually typed array literal expression containing one or more spread elements, // an element expression at index N is contextually typed by the numeric index type of the contextual type, if any. -var spr = [1, 2, 3].concat(array); -var spr1 = [1, 2, 3].concat(tup); -var spr2 = [1, 2, 3].concat(tup); // Error +var spr = __spreadArrays([1, 2, 3], array); +var spr1 = __spreadArrays([1, 2, 3], tup); +var spr2 = __spreadArrays([1, 2, 3], tup); // Error diff --git a/tests/baselines/reference/arrayLiteralSpread.js b/tests/baselines/reference/arrayLiteralSpread.js index 3561189671e84..bf86204156a16 100644 --- a/tests/baselines/reference/arrayLiteralSpread.js +++ b/tests/baselines/reference/arrayLiteralSpread.js @@ -24,20 +24,27 @@ function f2() { //// [arrayLiteralSpread.js] +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; function f0() { var a = [1, 2, 3]; - var a1 = a.slice(); - var a2 = [1].concat(a); - var a3 = [1, 2].concat(a); - var a4 = a.concat([1]); - var a5 = a.concat([1, 2]); - var a6 = [1, 2].concat(a, [1, 2]); - var a7 = [1].concat(a, [2], a); - var a8 = a.concat(a, a); + var a1 = __spreadArrays(a); + var a2 = __spreadArrays([1], a); + var a3 = __spreadArrays([1, 2], a); + var a4 = __spreadArrays(a, [1]); + var a5 = __spreadArrays(a, [1, 2]); + var a6 = __spreadArrays([1, 2], a, [1, 2]); + var a7 = __spreadArrays([1], a, [2], a); + var a8 = __spreadArrays(a, a, a); } function f1() { var a = [1, 2, 3]; - var b = ["hello"].concat(a, [true]); + var b = __spreadArrays(["hello"], a, [true]); var b; } function f2() { diff --git a/tests/baselines/reference/arrayLiterals2ES5.js b/tests/baselines/reference/arrayLiterals2ES5.js index 6a81ab465a2f1..2626be0834381 100644 --- a/tests/baselines/reference/arrayLiterals2ES5.js +++ b/tests/baselines/reference/arrayLiterals2ES5.js @@ -62,14 +62,21 @@ var d9 = [[...temp1], ...["hello"]]; // Elisionopt SpreadElement // ElementList, Elisionopt AssignmentExpression // ElementList, Elisionopt SpreadElement +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; // SpreadElement: // ... AssignmentExpression var a0 = [, , 2, 3, 4]; var a1 = ["hello", "world"]; -var a2 = [, , ].concat(a0, ["hello"]); -var a3 = [, ].concat(a0); +var a2 = __spreadArrays([, , ], a0, ["hello"]); +var a3 = __spreadArrays([, ], a0); var a4 = [function () { return 1; },]; -var a5 = a0.concat([,]); +var a5 = __spreadArrays(a0, [,]); // Each element expression in a non-empty array literal is processed as follows: // - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) // by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal, @@ -92,13 +99,13 @@ var temp1 = [1, 2, 3]; var temp2 = [[1, 2, 3], ["hello", "string"]]; var temp3 = [undefined, null, undefined]; var temp4 = []; -var d0 = [1, true].concat(temp); // has type (string|number|boolean)[] -var d1 = temp.slice(); // has type string[] -var d2 = temp1.slice(); -var d3 = temp1.slice(); -var d4 = temp.concat(temp1); -var d5 = temp3.slice(); -var d6 = temp4.slice(); -var d7 = temp1.slice(); -var d8 = [temp1.slice()]; -var d9 = [temp1.slice()].concat(["hello"]); +var d0 = __spreadArrays([1, true], temp); // has type (string|number|boolean)[] +var d1 = __spreadArrays(temp); // has type string[] +var d2 = __spreadArrays(temp1); +var d3 = __spreadArrays(temp1); +var d4 = __spreadArrays(temp, temp1); +var d5 = __spreadArrays(temp3); +var d6 = __spreadArrays(temp4); +var d7 = __spreadArrays(temp1); +var d8 = [__spreadArrays(temp1)]; +var d9 = __spreadArrays([__spreadArrays(temp1)], ["hello"]); diff --git a/tests/baselines/reference/arrayLiterals3.js b/tests/baselines/reference/arrayLiterals3.js index 4769c06998827..754bd1fba1e71 100644 --- a/tests/baselines/reference/arrayLiterals3.js +++ b/tests/baselines/reference/arrayLiterals3.js @@ -40,6 +40,13 @@ var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number // - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) // by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal, // the element expression is contextually typed by the type of that property. +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; // The resulting type an array literal expression is determined as follows: // - If the array literal contains no spread elements and is contextually typed by a tuple-like type, // the resulting type is a tuple type constructed from the types of the element expressions. @@ -55,6 +62,6 @@ var _a = [1, 2, "string", true], b1 = _a[0], b2 = _a[1]; var temp = ["s", "t", "r"]; var temp1 = [1, 2, 3]; var temp2 = [[1, 2, 3], ["hello", "string"]]; -var c0 = temp2.slice(); // Error -var c1 = temp1.slice(); // Error cannot assign number[] to [number, number, number] -var c2 = temp1.concat(temp); // Error cannot assign (number|string)[] to number[] +var c0 = __spreadArrays(temp2); // Error +var c1 = __spreadArrays(temp1); // Error cannot assign number[] to [number, number, number] +var c2 = __spreadArrays(temp1, temp); // Error cannot assign (number|string)[] to number[] diff --git a/tests/baselines/reference/callOverload.js b/tests/baselines/reference/callOverload.js index baab0c5d033b9..05cb5acff8771 100644 --- a/tests/baselines/reference/callOverload.js +++ b/tests/baselines/reference/callOverload.js @@ -12,10 +12,17 @@ withRest(); withRest(...n); //// [callOverload.js] +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; var n; fn(1); // no error fn(1, 2, 3, 4); takeTwo(1, 2, 3, 4); -withRest.apply(void 0, ['a'].concat(n)); // no error +withRest.apply(void 0, __spreadArrays(['a'], n)); // no error withRest(); withRest.apply(void 0, n); diff --git a/tests/baselines/reference/callWithSpread.js b/tests/baselines/reference/callWithSpread.js index f8f1959d2bb34..ee0ab6fe8a716 100644 --- a/tests/baselines/reference/callWithSpread.js +++ b/tests/baselines/reference/callWithSpread.js @@ -72,6 +72,13 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; var _a, _b, _c, _d, _e, _f, _g; function foo(x, y) { var z = []; @@ -84,23 +91,23 @@ var z; var obj; var xa; foo(1, 2, "abc"); -foo.apply(void 0, [1, 2].concat(a)); -foo.apply(void 0, [1, 2].concat(a, ["abc"])); +foo.apply(void 0, __spreadArrays([1, 2], a)); +foo.apply(void 0, __spreadArrays([1, 2], a, ["abc"])); obj.foo(1, 2, "abc"); -obj.foo.apply(obj, [1, 2].concat(a)); -obj.foo.apply(obj, [1, 2].concat(a, ["abc"])); -obj.foo.apply(obj, [1, 2].concat(a)).foo(1, 2, "abc"); -(_a = obj.foo.apply(obj, [1, 2].concat(a))).foo.apply(_a, [1, 2].concat(a)); -(_b = obj.foo.apply(obj, [1, 2].concat(a))).foo.apply(_b, [1, 2].concat(a, ["abc"])); +obj.foo.apply(obj, __spreadArrays([1, 2], a)); +obj.foo.apply(obj, __spreadArrays([1, 2], a, ["abc"])); +obj.foo.apply(obj, __spreadArrays([1, 2], a)).foo(1, 2, "abc"); +(_a = obj.foo.apply(obj, __spreadArrays([1, 2], a))).foo.apply(_a, __spreadArrays([1, 2], a)); +(_b = obj.foo.apply(obj, __spreadArrays([1, 2], a))).foo.apply(_b, __spreadArrays([1, 2], a, ["abc"])); (obj.foo)(1, 2, "abc"); -obj.foo.apply(obj, [1, 2].concat(a)); -obj.foo.apply(obj, [1, 2].concat(a, ["abc"])); -(obj.foo.apply(obj, [1, 2].concat(a)).foo)(1, 2, "abc"); -(_c = obj.foo.apply(obj, [1, 2].concat(a))).foo.apply(_c, [1, 2].concat(a)); -(_d = obj.foo.apply(obj, [1, 2].concat(a))).foo.apply(_d, [1, 2].concat(a, ["abc"])); +obj.foo.apply(obj, __spreadArrays([1, 2], a)); +obj.foo.apply(obj, __spreadArrays([1, 2], a, ["abc"])); +(obj.foo.apply(obj, __spreadArrays([1, 2], a)).foo)(1, 2, "abc"); +(_c = obj.foo.apply(obj, __spreadArrays([1, 2], a))).foo.apply(_c, __spreadArrays([1, 2], a)); +(_d = obj.foo.apply(obj, __spreadArrays([1, 2], a))).foo.apply(_d, __spreadArrays([1, 2], a, ["abc"])); xa[1].foo(1, 2, "abc"); -(_e = xa[1]).foo.apply(_e, [1, 2].concat(a)); -(_f = xa[1]).foo.apply(_f, [1, 2].concat(a, ["abc"])); +(_e = xa[1]).foo.apply(_e, __spreadArrays([1, 2], a)); +(_f = xa[1]).foo.apply(_f, __spreadArrays([1, 2], a, ["abc"])); (_g = xa[1]).foo.apply(_g, [1, 2, "abc"]); var C = /** @class */ (function () { function C(x, y) { @@ -109,7 +116,7 @@ var C = /** @class */ (function () { z[_i - 2] = arguments[_i]; } this.foo(x, y); - this.foo.apply(this, [x, y].concat(z)); + this.foo.apply(this, __spreadArrays([x, y], z)); } C.prototype.foo = function (x, y) { var z = []; @@ -123,12 +130,12 @@ var D = /** @class */ (function (_super) { __extends(D, _super); function D() { var _this = _super.call(this, 1, 2) || this; - _this = _super.apply(this, [1, 2].concat(a)) || this; + _this = _super.apply(this, __spreadArrays([1, 2], a)) || this; return _this; } D.prototype.foo = function () { _super.prototype.foo.call(this, 1, 2); - _super.prototype.foo.apply(this, [1, 2].concat(a)); + _super.prototype.foo.apply(this, __spreadArrays([1, 2], a)); }; return D; }(C)); diff --git a/tests/baselines/reference/callWithSpread2.js b/tests/baselines/reference/callWithSpread2.js index 2d0fd7f512e87..bf5bd87b6c569 100644 --- a/tests/baselines/reference/callWithSpread2.js +++ b/tests/baselines/reference/callWithSpread2.js @@ -38,24 +38,31 @@ prefix2("g", ...ns); //// [callWithSpread2.js] +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; // good all.apply(void 0, ns); weird.apply(void 0, ns); weird.apply(void 0, mixed); weird.apply(void 0, tuple); -prefix.apply(void 0, ["a"].concat(ns)); -rest.apply(void 0, ["d"].concat(ns)); +prefix.apply(void 0, __spreadArrays(["a"], ns)); +rest.apply(void 0, __spreadArrays(["d"], ns)); // extra arguments -normal.apply(void 0, ["g"].concat(ns)); +normal.apply(void 0, __spreadArrays(["g"], ns)); thunk.apply(void 0, ns); // bad all.apply(void 0, mixed); all.apply(void 0, tuple); -prefix.apply(void 0, ["b"].concat(mixed)); -prefix.apply(void 0, ["c"].concat(tuple)); -rest.apply(void 0, ["e"].concat(mixed)); -rest.apply(void 0, ["f"].concat(tuple)); +prefix.apply(void 0, __spreadArrays(["b"], mixed)); +prefix.apply(void 0, __spreadArrays(["c"], tuple)); +rest.apply(void 0, __spreadArrays(["e"], mixed)); +rest.apply(void 0, __spreadArrays(["f"], tuple)); prefix.apply(void 0, ns); // required parameters are required prefix.apply(void 0, mixed); prefix.apply(void 0, tuple); -prefix2.apply(void 0, ["g"].concat(ns)); +prefix2.apply(void 0, __spreadArrays(["g"], ns)); diff --git a/tests/baselines/reference/callWithSpread3.js b/tests/baselines/reference/callWithSpread3.js index 5581a77189fc0..bcb30625f46ce 100644 --- a/tests/baselines/reference/callWithSpread3.js +++ b/tests/baselines/reference/callWithSpread3.js @@ -11,9 +11,16 @@ takeTwo(...t2, 'a'); // error on 'a' takeTwo(...t3); // error on ...t3 //// [callWithSpread3.js] -takeTwo.apply(void 0, ['a'].concat(t2)); // error on ...t2 -takeTwo.apply(void 0, ['a', 'b', 'c'].concat(t2)); // error on 'c' and ...t2 -takeTwo.apply(void 0, ['a', 'b'].concat(t2, ['c'])); // error on ...t2 and 'c' -takeTwo.apply(void 0, ['a', 'b', 'c'].concat(t2, ['d'])); // error on 'c', ...t2 and 'd' -takeTwo.apply(void 0, t2.concat(['a'])); // error on 'a' +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; +takeTwo.apply(void 0, __spreadArrays(['a'], t2)); // error on ...t2 +takeTwo.apply(void 0, __spreadArrays(['a', 'b', 'c'], t2)); // error on 'c' and ...t2 +takeTwo.apply(void 0, __spreadArrays(['a', 'b'], t2, ['c'])); // error on ...t2 and 'c' +takeTwo.apply(void 0, __spreadArrays(['a', 'b', 'c'], t2, ['d'])); // error on 'c', ...t2 and 'd' +takeTwo.apply(void 0, __spreadArrays(t2, ['a'])); // error on 'a' takeTwo.apply(void 0, t3); // error on ...t3 diff --git a/tests/baselines/reference/constAssertions.js b/tests/baselines/reference/constAssertions.js index 9f173987d226e..21369cb3423f5 100644 --- a/tests/baselines/reference/constAssertions.js +++ b/tests/baselines/reference/constAssertions.js @@ -200,8 +200,8 @@ declare let p4: readonly [readonly [readonly [readonly [10]]]]; declare let x1: { readonly x: 10; readonly y: readonly [20, 30]; - z: { - a: { + readonly z: { + readonly a: { readonly b: 42; }; }; diff --git a/tests/baselines/reference/constAssertions.types b/tests/baselines/reference/constAssertions.types index b1f90df15f06d..b02988aea1b6d 100644 --- a/tests/baselines/reference/constAssertions.types +++ b/tests/baselines/reference/constAssertions.types @@ -281,7 +281,7 @@ let p4 = [[[[10]]]] as const; >10 : 10 let x1 = { x: 10, y: [20, 30], z: { a: { b: 42 } } } as const; ->x1 : { readonly x: 10; readonly y: readonly [20, 30]; z: { a: { readonly b: 42; }; }; } +>x1 : { readonly x: 10; readonly y: readonly [20, 30]; readonly z: { readonly a: { readonly b: 42; }; }; } >{ x: 10, y: [20, 30], z: { a: { b: 42 } } } as const : { readonly x: 10; readonly y: readonly [20, 30]; readonly z: { readonly a: { readonly b: 42; }; }; } >{ x: 10, y: [20, 30], z: { a: { b: 42 } } } : { readonly x: 10; readonly y: readonly [20, 30]; readonly z: { readonly a: { readonly b: 42; }; }; } >x : 10 diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js index 4f071b5e5ecd1..d6ab7e9444b3e 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js @@ -70,6 +70,13 @@ var [c14, c15, c16] = [1, 2, "string"]; * AssignmentRestElement: * ... LeftHandSideExpression */ +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; // In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. // An expression of type S is considered assignable to an assignment target V if one of the following is true // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, @@ -88,7 +95,7 @@ var _e = foo(), b6 = _e[0], b7 = _e[1]; var b8 = foo().slice(0); // S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. var temp = [1, 2, 3]; -var _f = temp.slice(), c0 = _f[0], c1 = _f[1]; +var _f = __spreadArrays(temp), c0 = _f[0], c1 = _f[1]; var c2 = [][0]; var _g = [[[]], [[[[]]]]], c3 = _g[0][0][0], c4 = _g[1][0][0][0][0]; var _h = [[1], true], c5 = _h[0][0], c6 = _h[1]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js index 223090ea8caa9..97ad0fd035b62 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js @@ -35,6 +35,13 @@ function foo(idx: number): F { var [c4, c5, c6] = foo(1); // Error //// [destructuringArrayBindingPatternAndAssignment2.js] +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, // S is the type Any, or var _a = [], a0 = _a[0][0], a1 = _a[1][0][0]; // Error @@ -50,8 +57,8 @@ var _c = bar(), _d = _c[0], b3 = _d === void 0 ? "string" : _d, b4 = _c[1], b5 = // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, // S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. var temp = [1, 2, 3]; -var _e = temp.slice(), c0 = _e[0], c1 = _e[1]; // Error -var _f = temp.slice(), c2 = _f[0], c3 = _f[1]; // Error +var _e = __spreadArrays(temp), c0 = _e[0], c1 = _e[1]; // Error +var _f = __spreadArrays(temp), c2 = _f[0], c3 = _f[1]; // Error function foo(idx) { return { 2: true diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.js b/tests/baselines/reference/destructuringVariableDeclaration1ES5.js index 6d731538d186c..6ab85ff6388f9 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5.js +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.js @@ -42,6 +42,13 @@ var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } //// [destructuringVariableDeclaration1ES5.js] +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; // The type T associated with a destructuring variable declaration is determined as follows: // If the declaration includes a type annotation, T is that type. var _a = { a1: 10, a2: "world" }, a1 = _a.a1, a2 = _a.a2; @@ -66,7 +73,7 @@ var _m = [1, "string"], d1 = _m[0], d2 = _m[1]; // Otherwise, if S is a tuple- like type (section 3.3.3): // Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. var temp1 = [true, false, true]; -var _o = [1, "string"].concat(temp1), d3 = _o[0], d4 = _o[1]; +var _o = __spreadArrays([1, "string"], temp1), d3 = _o[0], d4 = _o[1]; // Combining both forms of destructuring, var _p = { e: [1, 2, { b1: 4, b4: 0 }] }.e, e1 = _p[0], e2 = _p[1], _q = _p[2], e3 = _q === void 0 ? { b1: 1000, b4: 200 } : _q; var _r = { f: [1, 2, { f3: 4, f5: 0 }] }.f, f1 = _r[0], f2 = _r[1], _s = _r[2], f4 = _s.f3, f5 = _s.f5; diff --git a/tests/baselines/reference/es5-asyncFunctionArrayLiterals.js b/tests/baselines/reference/es5-asyncFunctionArrayLiterals.js index d3f570d5882f8..3c16f785d3e56 100644 --- a/tests/baselines/reference/es5-asyncFunctionArrayLiterals.js +++ b/tests/baselines/reference/es5-asyncFunctionArrayLiterals.js @@ -67,7 +67,7 @@ function arrayLiteral2() { switch (_a.label) { case 0: return [4 /*yield*/, y]; case 1: - x = (_a.sent()).concat([z]); + x = __spreadArrays.apply(void 0, [(_a.sent()), [z]]); return [2 /*return*/]; } }); @@ -75,14 +75,14 @@ function arrayLiteral2() { } function arrayLiteral3() { return __awaiter(this, void 0, void 0, function () { - var _a, _b; - return __generator(this, function (_c) { - switch (_c.label) { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { case 0: - _b = (_a = y).concat; + _a = [y]; return [4 /*yield*/, z]; case 1: - x = _b.apply(_a, [[_c.sent()]]); + x = __spreadArrays.apply(void 0, _a.concat([[_b.sent()]])); return [2 /*return*/]; } }); @@ -94,7 +94,7 @@ function arrayLiteral4() { switch (_a.label) { case 0: return [4 /*yield*/, y]; case 1: - x = [_a.sent()].concat(z); + x = __spreadArrays.apply(void 0, [[_a.sent()], z]); return [2 /*return*/]; } }); @@ -102,14 +102,14 @@ function arrayLiteral4() { } function arrayLiteral5() { return __awaiter(this, void 0, void 0, function () { - var _a, _b; - return __generator(this, function (_c) { - switch (_c.label) { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { case 0: - _b = (_a = [y]).concat; + _a = [[y]]; return [4 /*yield*/, z]; case 1: - x = _b.apply(_a, [(_c.sent())]); + x = __spreadArrays.apply(void 0, _a.concat([(_b.sent())])); return [2 /*return*/]; } }); diff --git a/tests/baselines/reference/es5-asyncFunctionCallExpressions.js b/tests/baselines/reference/es5-asyncFunctionCallExpressions.js index 452a5e1cc9018..20120ae04e439 100644 --- a/tests/baselines/reference/es5-asyncFunctionCallExpressions.js +++ b/tests/baselines/reference/es5-asyncFunctionCallExpressions.js @@ -146,7 +146,7 @@ function callExpression4() { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, x.apply(void 0, y.concat([z]))]; + case 0: return [4 /*yield*/, x.apply(void 0, __spreadArrays(y, [z]))]; case 1: _a.sent(); return [2 /*return*/]; @@ -160,7 +160,7 @@ function callExpression5() { switch (_a.label) { case 0: return [4 /*yield*/, x]; case 1: - (_a.sent()).apply(void 0, y.concat([z])); + (_a.sent()).apply(void 0, __spreadArrays(y, [z])); return [2 /*return*/]; } }); @@ -176,7 +176,7 @@ function callExpression6() { _c = [void 0]; return [4 /*yield*/, y]; case 1: - _b.apply(_a, _c.concat([(_d.sent()).concat([z])])); + _b.apply(_a, _c.concat([__spreadArrays.apply(void 0, [(_d.sent()), [z]])])); return [2 /*return*/]; } }); @@ -184,16 +184,16 @@ function callExpression6() { } function callExpression7() { return __awaiter(this, void 0, void 0, function () { - var _a, _b, _c, _d, _e; - return __generator(this, function (_f) { - switch (_f.label) { + var _a, _b, _c, _d; + return __generator(this, function (_e) { + switch (_e.label) { case 0: _b = (_a = x).apply; _c = [void 0]; - _e = (_d = y).concat; + _d = [y]; return [4 /*yield*/, z]; case 1: - _b.apply(_a, _c.concat([_e.apply(_d, [[_f.sent()]])])); + _b.apply(_a, _c.concat([__spreadArrays.apply(void 0, _d.concat([[_e.sent()]]))])); return [2 /*return*/]; } }); @@ -209,7 +209,7 @@ function callExpression8() { _c = [void 0]; return [4 /*yield*/, y]; case 1: - _b.apply(_a, _c.concat([[_d.sent()].concat(z)])); + _b.apply(_a, _c.concat([__spreadArrays.apply(void 0, [[_d.sent()], z])])); return [2 /*return*/]; } }); @@ -217,16 +217,16 @@ function callExpression8() { } function callExpression9() { return __awaiter(this, void 0, void 0, function () { - var _a, _b, _c, _d, _e; - return __generator(this, function (_f) { - switch (_f.label) { + var _a, _b, _c, _d; + return __generator(this, function (_e) { + switch (_e.label) { case 0: _b = (_a = x).apply; _c = [void 0]; - _e = (_d = [y]).concat; + _d = [[y]]; return [4 /*yield*/, z]; case 1: - _b.apply(_a, _c.concat([_e.apply(_d, [(_f.sent())])])); + _b.apply(_a, _c.concat([__spreadArrays.apply(void 0, _d.concat([(_e.sent())]))])); return [2 /*return*/]; } }); diff --git a/tests/baselines/reference/es5-asyncFunctionNewExpressions.js b/tests/baselines/reference/es5-asyncFunctionNewExpressions.js index ba1331afd205a..36c38fe5ec9d6 100644 --- a/tests/baselines/reference/es5-asyncFunctionNewExpressions.js +++ b/tests/baselines/reference/es5-asyncFunctionNewExpressions.js @@ -145,7 +145,7 @@ function newExpression4() { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, new (x.bind.apply(x, [void 0].concat(y, [z])))()]; + case 0: return [4 /*yield*/, new (x.bind.apply(x, __spreadArrays([void 0], y, [z])))()]; case 1: _a.sent(); return [2 /*return*/]; @@ -160,7 +160,7 @@ function newExpression5() { switch (_b.label) { case 0: return [4 /*yield*/, x]; case 1: - new ((_a = (_b.sent())).bind.apply(_a, [void 0].concat(y, [z])))(); + new ((_a = (_b.sent())).bind.apply(_a, __spreadArrays([void 0], y, [z])))(); return [2 /*return*/]; } }); @@ -168,16 +168,16 @@ function newExpression5() { } function newExpression6() { return __awaiter(this, void 0, void 0, function () { - var _a, _b, _c, _d, _e; - return __generator(this, function (_f) { - switch (_f.label) { + var _a, _b, _c, _d; + return __generator(this, function (_e) { + switch (_e.label) { case 0: _b = (_a = x.bind).apply; _c = [x]; - _e = (_d = [void 0]).concat; + _d = [[void 0]]; return [4 /*yield*/, y]; case 1: - new (_b.apply(_a, _c.concat([_e.apply(_d, [(_f.sent()), [z]])])))(); + new (_b.apply(_a, _c.concat([__spreadArrays.apply(void 0, _d.concat([(_e.sent()), [z]]))])))(); return [2 /*return*/]; } }); @@ -185,17 +185,16 @@ function newExpression6() { } function newExpression7() { return __awaiter(this, void 0, void 0, function () { - var _a, _b, _c, _d, _e, _f; - return __generator(this, function (_g) { - switch (_g.label) { + var _a, _b, _c, _d; + return __generator(this, function (_e) { + switch (_e.label) { case 0: _b = (_a = x.bind).apply; _c = [x]; - _e = (_d = [void 0]).concat; - _f = [y]; + _d = [[void 0], y]; return [4 /*yield*/, z]; case 1: - new (_b.apply(_a, _c.concat([_e.apply(_d, _f.concat([[_g.sent()]]))])))(); + new (_b.apply(_a, _c.concat([__spreadArrays.apply(void 0, _d.concat([[_e.sent()]]))])))(); return [2 /*return*/]; } }); @@ -212,7 +211,7 @@ function newExpression8() { _d = [void 0]; return [4 /*yield*/, y]; case 1: - new (_b.apply(_a, _c.concat([_d.concat([_e.sent()]).concat(z)])))(); + new (_b.apply(_a, _c.concat([__spreadArrays.apply(void 0, [_d.concat([_e.sent()]), z])])))(); return [2 /*return*/]; } }); @@ -220,16 +219,16 @@ function newExpression8() { } function newExpression9() { return __awaiter(this, void 0, void 0, function () { - var _a, _b, _c, _d, _e; - return __generator(this, function (_f) { - switch (_f.label) { + var _a, _b, _c, _d; + return __generator(this, function (_e) { + switch (_e.label) { case 0: _b = (_a = x.bind).apply; _c = [x]; - _e = (_d = [void 0, y]).concat; + _d = [[void 0, y]]; return [4 /*yield*/, z]; case 1: - new (_b.apply(_a, _c.concat([_e.apply(_d, [(_f.sent())])])))(); + new (_b.apply(_a, _c.concat([__spreadArrays.apply(void 0, _d.concat([(_e.sent())]))])))(); return [2 /*return*/]; } }); diff --git a/tests/baselines/reference/genericRestParameters1.js b/tests/baselines/reference/genericRestParameters1.js index 2932f2b96cbcd..eecb906462f30 100644 --- a/tests/baselines/reference/genericRestParameters1.js +++ b/tests/baselines/reference/genericRestParameters1.js @@ -167,53 +167,60 @@ ff1 = ff4; // Error //// [genericRestParameters1.js] "use strict"; +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; f1 = f2; f2 = f1; f1(42, "hello", true); f1(t3[0], t3[1], t3[2]); f1.apply(void 0, t3); -f1.apply(void 0, [42].concat(t2)); -f1.apply(void 0, [42, "hello"].concat(t1)); -f1.apply(void 0, [42, "hello", true].concat(t0)); +f1.apply(void 0, __spreadArrays([42], t2)); +f1.apply(void 0, __spreadArrays([42, "hello"], t1)); +f1.apply(void 0, __spreadArrays([42, "hello", true], t0)); f1(ns[0], ns[1], true); -f1.apply(void 0, ns.concat([true])); // Error, tuple spread only expanded when last +f1.apply(void 0, __spreadArrays(ns, [true])); // Error, tuple spread only expanded when last f2(42, "hello", true); f2(t3[0], t3[1], t3[2]); f2.apply(void 0, t3); -f2.apply(void 0, [42].concat(t2)); -f2.apply(void 0, [42, "hello"].concat(t1)); -f2.apply(void 0, [42, "hello", true].concat(t0)); +f2.apply(void 0, __spreadArrays([42], t2)); +f2.apply(void 0, __spreadArrays([42, "hello"], t1)); +f2.apply(void 0, __spreadArrays([42, "hello", true], t0)); f2(ns[0], ns[1], true); -f2.apply(void 0, ns.concat([true])); // Error, tuple spread only expanded when last +f2.apply(void 0, __spreadArrays(ns, [true])); // Error, tuple spread only expanded when last var x10 = f10(42, "hello", true); // [number, string, boolean] var x11 = f10(42, "hello"); // [number, string] var x12 = f10(42); // [number] var x13 = f10(); // [] var x14 = f10.apply(void 0, t3); // [number, string, boolean] -var x15 = f10.apply(void 0, [42].concat(t2)); // [number, string, boolean] -var x16 = f10.apply(void 0, [42, "hello"].concat(t1)); // [number, string, boolean] -var x17 = f10.apply(void 0, [42, "hello", true].concat(t0)); // [number, string, boolean] -var x18 = f10.apply(void 0, ns.concat([true])); // (string | number | boolean)[] +var x15 = f10.apply(void 0, __spreadArrays([42], t2)); // [number, string, boolean] +var x16 = f10.apply(void 0, __spreadArrays([42, "hello"], t1)); // [number, string, boolean] +var x17 = f10.apply(void 0, __spreadArrays([42, "hello", true], t0)); // [number, string, boolean] +var x18 = f10.apply(void 0, __spreadArrays(ns, [true])); // (string | number | boolean)[] function g10(u, v) { var x1 = f10.apply(void 0, u); // U var x2 = f10.apply(void 0, v); // V - var x3 = f10.apply(void 0, [1].concat(u)); // [number, ...string[]] - var x4 = f10.apply(void 0, u.concat(v)); // (string | number)[] + var x3 = f10.apply(void 0, __spreadArrays([1], u)); // [number, ...string[]] + var x4 = f10.apply(void 0, __spreadArrays(u, v)); // (string | number)[] } var z10 = f11(42, "hello", true); // [42, "hello", true] var z11 = f11(42, "hello"); // [42, "hello"] var z12 = f11(42); // [42] var z13 = f11(); // [] var z14 = f11.apply(void 0, t3); // [number, string, boolean] -var z15 = f11.apply(void 0, [42].concat(t2)); // [42, string, boolean] -var z16 = f11.apply(void 0, [42, "hello"].concat(t1)); // [42, "hello", boolean] -var z17 = f11.apply(void 0, [42, "hello", true].concat(t0)); // [42, "hello", true] -var z18 = f11.apply(void 0, ns.concat([true])); // (string | number | true)[] +var z15 = f11.apply(void 0, __spreadArrays([42], t2)); // [42, string, boolean] +var z16 = f11.apply(void 0, __spreadArrays([42, "hello"], t1)); // [42, "hello", boolean] +var z17 = f11.apply(void 0, __spreadArrays([42, "hello", true], t0)); // [42, "hello", true] +var z18 = f11.apply(void 0, __spreadArrays(ns, [true])); // (string | number | true)[] function g11(u, v) { var x1 = f11.apply(void 0, u); // U var x2 = f11.apply(void 0, v); // V - var x3 = f11.apply(void 0, [1].concat(u)); // [1, ...string[]] - var x4 = f11.apply(void 0, u.concat(v)); // (string | number)[] + var x3 = f11.apply(void 0, __spreadArrays([1], u)); // [1, ...string[]] + var x4 = f11.apply(void 0, __spreadArrays(u, v)); // (string | number)[] } function call(f) { var args = []; @@ -239,7 +246,7 @@ function bind(f, x) { for (var _i = 0; _i < arguments.length; _i++) { rest[_i] = arguments[_i]; } - return f.apply(void 0, [x].concat(rest)); + return f.apply(void 0, __spreadArrays([x], rest)); }; } var f21 = bind(f20, 42); // (y: string, z: boolean) => string[] diff --git a/tests/baselines/reference/genericRestParameters2.js b/tests/baselines/reference/genericRestParameters2.js index 3c00a7c2a3a3f..a958ee2da4d94 100644 --- a/tests/baselines/reference/genericRestParameters2.js +++ b/tests/baselines/reference/genericRestParameters2.js @@ -81,46 +81,53 @@ type T12 = P1<(x: number, y: number) => void>; //// [genericRestParameters2.js] "use strict"; +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; f10(42, "hello"); f10(42, "hello", true); f10(42, "hello", true, false); f10(t1[0], t1[1], t1[2], t1[3]); f10.apply(void 0, t1); -f10.apply(void 0, [42].concat(t2)); -f10.apply(void 0, [42, "hello"].concat(t3)); -f10.apply(void 0, [42, "hello", true].concat(t4)); -f10.apply(void 0, [42, "hello", true].concat(t4, [false], t3)); +f10.apply(void 0, __spreadArrays([42], t2)); +f10.apply(void 0, __spreadArrays([42, "hello"], t3)); +f10.apply(void 0, __spreadArrays([42, "hello", true], t4)); +f10.apply(void 0, __spreadArrays([42, "hello", true], t4, [false], t3)); f11(42, "hello"); f11(42, "hello", true); f11(42, "hello", true, false); f11(t1[0], t1[1], t1[2], t1[3]); f11.apply(void 0, t1); -f11.apply(void 0, [42].concat(t2)); -f11.apply(void 0, [42, "hello"].concat(t3)); -f11.apply(void 0, [42, "hello", true].concat(t4)); -f11.apply(void 0, [42, "hello", true].concat(t4, [false], t3)); +f11.apply(void 0, __spreadArrays([42], t2)); +f11.apply(void 0, __spreadArrays([42, "hello"], t3)); +f11.apply(void 0, __spreadArrays([42, "hello", true], t4)); +f11.apply(void 0, __spreadArrays([42, "hello", true], t4, [false], t3)); f12(42, "hello"); f12(42, "hello", true); f12(42, "hello", true, false); f12(t1[0], t1[1], t1[2], t1[3]); f12.apply(void 0, t1); -f12.apply(void 0, [42].concat(t2)); -f12.apply(void 0, [42, "hello"].concat(t3)); -f12.apply(void 0, [42, "hello", true].concat(t4)); -f12.apply(void 0, [42, "hello", true].concat(t4, [false], t3)); +f12.apply(void 0, __spreadArrays([42], t2)); +f12.apply(void 0, __spreadArrays([42, "hello"], t3)); +f12.apply(void 0, __spreadArrays([42, "hello", true], t4)); +f12.apply(void 0, __spreadArrays([42, "hello", true], t4, [false], t3)); f13(42, "hello"); f13(42, "hello", true); f13(42, "hello", true, false); f13(t1[0], t1[1], t1[2], t1[3]); f13.apply(void 0, t1); -f13.apply(void 0, [42].concat(t2)); -f13.apply(void 0, [42, "hello"].concat(t3)); -f13.apply(void 0, [42, "hello", true].concat(t4)); -f13.apply(void 0, [42, "hello", true].concat(t4, [false], t3)); +f13.apply(void 0, __spreadArrays([42], t2)); +f13.apply(void 0, __spreadArrays([42, "hello"], t3)); +f13.apply(void 0, __spreadArrays([42, "hello", true], t4)); +f13.apply(void 0, __spreadArrays([42, "hello", true], t4, [false], t3)); f20.apply(void 0, t1); -f20.apply(void 0, [42].concat(t2)); -f20.apply(void 0, [42, "hello"].concat(t3)); -f20.apply(void 0, [42, "hello"].concat(t2, [true])); +f20.apply(void 0, __spreadArrays([42], t2)); +f20.apply(void 0, __spreadArrays([42, "hello"], t3)); +f20.apply(void 0, __spreadArrays([42, "hello"], t2, [true])); //// [genericRestParameters2.d.ts] diff --git a/tests/baselines/reference/genericRestParameters3.js b/tests/baselines/reference/genericRestParameters3.js index 132edcbefb686..48a54e399f0c0 100644 --- a/tests/baselines/reference/genericRestParameters3.js +++ b/tests/baselines/reference/genericRestParameters3.js @@ -56,9 +56,16 @@ hmm("what"); // no error? A = [] | [number, string] ? //// [genericRestParameters3.js] "use strict"; +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; f1("foo", "abc"); f1("foo", 10, true); -f1.apply(void 0, ["foo"].concat(tt)); +f1.apply(void 0, __spreadArrays(["foo"], tt)); f1("foo", 10); // Error f1("foo"); // Error f2 = f1; diff --git a/tests/baselines/reference/indexingTypesWithNever.types b/tests/baselines/reference/indexingTypesWithNever.types index bf141ae0059e4..c8e2afdabdc12 100644 --- a/tests/baselines/reference/indexingTypesWithNever.types +++ b/tests/baselines/reference/indexingTypesWithNever.types @@ -69,8 +69,8 @@ declare function genericFn3< // Should be never const result5 = genericFn3({ g: "gtest", h: "htest" }, "g", "h"); // 'g' & 'h' will reduce to never ->result5 : unknown ->genericFn3({ g: "gtest", h: "htest" }, "g", "h") : unknown +>result5 : never +>genericFn3({ g: "gtest", h: "htest" }, "g", "h") : never >genericFn3 : (obj: T, u: U, v: V) => T[U & V] >{ g: "gtest", h: "htest" } : { g: string; h: string; } >g : string diff --git a/tests/baselines/reference/inferTypes1.errors.txt b/tests/baselines/reference/inferTypes1.errors.txt index 1de0ca2562f8a..3779d91bf2b01 100644 --- a/tests/baselines/reference/inferTypes1.errors.txt +++ b/tests/baselines/reference/inferTypes1.errors.txt @@ -107,7 +107,7 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(145,40): error TS2322: type T50 = X3<{}>; // never type T51 = X3<{ a: (x: string) => void }>; // never type T52 = X3<{ a: (x: string) => void, b: (x: string) => void }>; // string - type T53 = X3<{ a: (x: number) => void, b: (x: string) => void }>; // string & number + type T53 = X3<{ a: (x: number) => void, b: (x: string) => void }>; // never type T54 = X3<{ a: (x: number) => void, b: () => void }>; // number type T60 = infer U; // Error diff --git a/tests/baselines/reference/inferTypes1.js b/tests/baselines/reference/inferTypes1.js index d15933264e934..01dc5a797f224 100644 --- a/tests/baselines/reference/inferTypes1.js +++ b/tests/baselines/reference/inferTypes1.js @@ -69,7 +69,7 @@ type X3 = T extends { a: (x: infer U) => void, b: (x: infer U) => void } ? U type T50 = X3<{}>; // never type T51 = X3<{ a: (x: string) => void }>; // never type T52 = X3<{ a: (x: string) => void, b: (x: string) => void }>; // string -type T53 = X3<{ a: (x: number) => void, b: (x: string) => void }>; // string & number +type T53 = X3<{ a: (x: number) => void, b: (x: string) => void }>; // never type T54 = X3<{ a: (x: number) => void, b: () => void }>; // number type T60 = infer U; // Error diff --git a/tests/baselines/reference/inferTypes1.symbols b/tests/baselines/reference/inferTypes1.symbols index 6abd0a2a36c23..609a0093290a7 100644 --- a/tests/baselines/reference/inferTypes1.symbols +++ b/tests/baselines/reference/inferTypes1.symbols @@ -297,7 +297,7 @@ type T52 = X3<{ a: (x: string) => void, b: (x: string) => void }>; // string >b : Symbol(b, Decl(inferTypes1.ts, 69, 39)) >x : Symbol(x, Decl(inferTypes1.ts, 69, 44)) -type T53 = X3<{ a: (x: number) => void, b: (x: string) => void }>; // string & number +type T53 = X3<{ a: (x: number) => void, b: (x: string) => void }>; // never >T53 : Symbol(T53, Decl(inferTypes1.ts, 69, 66)) >X3 : Symbol(X3, Decl(inferTypes1.ts, 63, 52)) >a : Symbol(a, Decl(inferTypes1.ts, 70, 15)) diff --git a/tests/baselines/reference/inferTypes1.types b/tests/baselines/reference/inferTypes1.types index 149ee287d6b6b..2696b520ae8a4 100644 --- a/tests/baselines/reference/inferTypes1.types +++ b/tests/baselines/reference/inferTypes1.types @@ -211,8 +211,8 @@ type T52 = X3<{ a: (x: string) => void, b: (x: string) => void }>; // string >b : (x: string) => void >x : string -type T53 = X3<{ a: (x: number) => void, b: (x: string) => void }>; // string & number ->T53 : number & string +type T53 = X3<{ a: (x: number) => void, b: (x: string) => void }>; // never +>T53 : never >a : (x: number) => void >x : number >b : (x: string) => void diff --git a/tests/baselines/reference/intersectionReduction.errors.txt b/tests/baselines/reference/intersectionReduction.errors.txt new file mode 100644 index 0000000000000..62631cca76b3c --- /dev/null +++ b/tests/baselines/reference/intersectionReduction.errors.txt @@ -0,0 +1,66 @@ +tests/cases/conformance/types/intersection/intersectionReduction.ts(40,1): error TS2322: Type 'any' is not assignable to type 'never'. +tests/cases/conformance/types/intersection/intersectionReduction.ts(41,1): error TS2322: Type 'any' is not assignable to type 'never'. + + +==== tests/cases/conformance/types/intersection/intersectionReduction.ts (2 errors) ==== + declare const sym1: unique symbol; + declare const sym2: unique symbol; + + type T1 = string & 'a'; // 'a' + type T2 = 'a' & string & 'b'; // never + type T3 = number & 10; // 10 + type T4 = 10 & number & 20; // never + type T5 = symbol & typeof sym1; // typeof sym1 + type T6 = typeof sym1 & symbol & typeof sym2; // never + type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never + + type T10 = string & ('a' | 'b'); // 'a' | 'b' + type T11 = (string | number) & ('a' | 10); // 'a' | 10 + + type N1 = 'a' & 'b'; + type N2 = { a: string } & null; + type N3 = { a: string } & undefined; + type N4 = string & number; + type N5 = number & object; + type N6 = symbol & string; + type N7 = void & string; + + type X = { x: string }; + + type X1 = X | 'a' & 'b'; + type X2 = X | { a: string } & null; + type X3 = X | { a: string } & undefined; + type X4 = X | string & number; + type X5 = X | number & object; + type X6 = X | symbol & string; + type X7 = X | void & string; + + // Repro from #31663 + + const x1 = { a: 'foo', b: 42 }; + const x2 = { a: 'foo', b: true }; + + declare let k: 'a' | 'b'; + + x1[k] = 'bar' as any; // Error + ~~~~~ +!!! error TS2322: Type 'any' is not assignable to type 'never'. + x2[k] = 'bar' as any; // Error + ~~~~~ +!!! error TS2322: Type 'any' is not assignable to type 'never'. + + const enum Tag1 {} + const enum Tag2 {} + + declare let s1: string & Tag1; + declare let s2: string & Tag2; + + declare let t1: string & Tag1 | undefined; + declare let t2: string & Tag2 | undefined; + + s1 = s2; + s2 = s1; + + t1 = t2; + t2 = t1; + \ No newline at end of file diff --git a/tests/baselines/reference/intersectionReduction.js b/tests/baselines/reference/intersectionReduction.js index 1b985a79b9f83..f2009cd9cc7e8 100644 --- a/tests/baselines/reference/intersectionReduction.js +++ b/tests/baselines/reference/intersectionReduction.js @@ -1,20 +1,69 @@ //// [intersectionReduction.ts] -// @strict - declare const sym1: unique symbol; declare const sym2: unique symbol; type T1 = string & 'a'; // 'a' -type T2 = 'a' & string & 'b'; // 'a' & 'b' +type T2 = 'a' & string & 'b'; // never type T3 = number & 10; // 10 -type T4 = 10 & number & 20; // 10 & 20 +type T4 = 10 & number & 20; // never type T5 = symbol & typeof sym1; // typeof sym1 -type T6 = typeof sym1 & symbol & typeof sym2; // typeof sym1 & typeof sym2 -type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // 'a' & 10 & typeof sym1 +type T6 = typeof sym1 & symbol & typeof sym2; // never +type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never type T10 = string & ('a' | 'b'); // 'a' | 'b' type T11 = (string | number) & ('a' | 10); // 'a' | 10 + +type N1 = 'a' & 'b'; +type N2 = { a: string } & null; +type N3 = { a: string } & undefined; +type N4 = string & number; +type N5 = number & object; +type N6 = symbol & string; +type N7 = void & string; + +type X = { x: string }; + +type X1 = X | 'a' & 'b'; +type X2 = X | { a: string } & null; +type X3 = X | { a: string } & undefined; +type X4 = X | string & number; +type X5 = X | number & object; +type X6 = X | symbol & string; +type X7 = X | void & string; + +// Repro from #31663 + +const x1 = { a: 'foo', b: 42 }; +const x2 = { a: 'foo', b: true }; + +declare let k: 'a' | 'b'; + +x1[k] = 'bar' as any; // Error +x2[k] = 'bar' as any; // Error + +const enum Tag1 {} +const enum Tag2 {} + +declare let s1: string & Tag1; +declare let s2: string & Tag2; + +declare let t1: string & Tag1 | undefined; +declare let t2: string & Tag2 | undefined; + +s1 = s2; +s2 = s1; + +t1 = t2; +t2 = t1; //// [intersectionReduction.js] -// @strict +// Repro from #31663 +var x1 = { a: 'foo', b: 42 }; +var x2 = { a: 'foo', b: true }; +x1[k] = 'bar'; // Error +x2[k] = 'bar'; // Error +s1 = s2; +s2 = s1; +t1 = t2; +t2 = t1; diff --git a/tests/baselines/reference/intersectionReduction.symbols b/tests/baselines/reference/intersectionReduction.symbols index 607ea1d6c480d..3e22d2e26965f 100644 --- a/tests/baselines/reference/intersectionReduction.symbols +++ b/tests/baselines/reference/intersectionReduction.symbols @@ -1,40 +1,156 @@ === tests/cases/conformance/types/intersection/intersectionReduction.ts === -// @strict - declare const sym1: unique symbol; ->sym1 : Symbol(sym1, Decl(intersectionReduction.ts, 2, 13)) +>sym1 : Symbol(sym1, Decl(intersectionReduction.ts, 0, 13)) declare const sym2: unique symbol; ->sym2 : Symbol(sym2, Decl(intersectionReduction.ts, 3, 13)) +>sym2 : Symbol(sym2, Decl(intersectionReduction.ts, 1, 13)) type T1 = string & 'a'; // 'a' ->T1 : Symbol(T1, Decl(intersectionReduction.ts, 3, 34)) +>T1 : Symbol(T1, Decl(intersectionReduction.ts, 1, 34)) -type T2 = 'a' & string & 'b'; // 'a' & 'b' ->T2 : Symbol(T2, Decl(intersectionReduction.ts, 5, 23)) +type T2 = 'a' & string & 'b'; // never +>T2 : Symbol(T2, Decl(intersectionReduction.ts, 3, 23)) type T3 = number & 10; // 10 ->T3 : Symbol(T3, Decl(intersectionReduction.ts, 6, 29)) +>T3 : Symbol(T3, Decl(intersectionReduction.ts, 4, 29)) -type T4 = 10 & number & 20; // 10 & 20 ->T4 : Symbol(T4, Decl(intersectionReduction.ts, 7, 22)) +type T4 = 10 & number & 20; // never +>T4 : Symbol(T4, Decl(intersectionReduction.ts, 5, 22)) type T5 = symbol & typeof sym1; // typeof sym1 ->T5 : Symbol(T5, Decl(intersectionReduction.ts, 8, 27)) ->sym1 : Symbol(sym1, Decl(intersectionReduction.ts, 2, 13)) +>T5 : Symbol(T5, Decl(intersectionReduction.ts, 6, 27)) +>sym1 : Symbol(sym1, Decl(intersectionReduction.ts, 0, 13)) -type T6 = typeof sym1 & symbol & typeof sym2; // typeof sym1 & typeof sym2 ->T6 : Symbol(T6, Decl(intersectionReduction.ts, 9, 31)) ->sym1 : Symbol(sym1, Decl(intersectionReduction.ts, 2, 13)) ->sym2 : Symbol(sym2, Decl(intersectionReduction.ts, 3, 13)) +type T6 = typeof sym1 & symbol & typeof sym2; // never +>T6 : Symbol(T6, Decl(intersectionReduction.ts, 7, 31)) +>sym1 : Symbol(sym1, Decl(intersectionReduction.ts, 0, 13)) +>sym2 : Symbol(sym2, Decl(intersectionReduction.ts, 1, 13)) -type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // 'a' & 10 & typeof sym1 ->T7 : Symbol(T7, Decl(intersectionReduction.ts, 10, 45)) ->sym1 : Symbol(sym1, Decl(intersectionReduction.ts, 2, 13)) +type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never +>T7 : Symbol(T7, Decl(intersectionReduction.ts, 8, 45)) +>sym1 : Symbol(sym1, Decl(intersectionReduction.ts, 0, 13)) type T10 = string & ('a' | 'b'); // 'a' | 'b' ->T10 : Symbol(T10, Decl(intersectionReduction.ts, 11, 60)) +>T10 : Symbol(T10, Decl(intersectionReduction.ts, 9, 60)) type T11 = (string | number) & ('a' | 10); // 'a' | 10 ->T11 : Symbol(T11, Decl(intersectionReduction.ts, 13, 32)) +>T11 : Symbol(T11, Decl(intersectionReduction.ts, 11, 32)) + +type N1 = 'a' & 'b'; +>N1 : Symbol(N1, Decl(intersectionReduction.ts, 12, 42)) + +type N2 = { a: string } & null; +>N2 : Symbol(N2, Decl(intersectionReduction.ts, 14, 20)) +>a : Symbol(a, Decl(intersectionReduction.ts, 15, 11)) + +type N3 = { a: string } & undefined; +>N3 : Symbol(N3, Decl(intersectionReduction.ts, 15, 31)) +>a : Symbol(a, Decl(intersectionReduction.ts, 16, 11)) + +type N4 = string & number; +>N4 : Symbol(N4, Decl(intersectionReduction.ts, 16, 36)) + +type N5 = number & object; +>N5 : Symbol(N5, Decl(intersectionReduction.ts, 17, 26)) + +type N6 = symbol & string; +>N6 : Symbol(N6, Decl(intersectionReduction.ts, 18, 26)) + +type N7 = void & string; +>N7 : Symbol(N7, Decl(intersectionReduction.ts, 19, 26)) + +type X = { x: string }; +>X : Symbol(X, Decl(intersectionReduction.ts, 20, 24)) +>x : Symbol(x, Decl(intersectionReduction.ts, 22, 10)) + +type X1 = X | 'a' & 'b'; +>X1 : Symbol(X1, Decl(intersectionReduction.ts, 22, 23)) +>X : Symbol(X, Decl(intersectionReduction.ts, 20, 24)) + +type X2 = X | { a: string } & null; +>X2 : Symbol(X2, Decl(intersectionReduction.ts, 24, 24)) +>X : Symbol(X, Decl(intersectionReduction.ts, 20, 24)) +>a : Symbol(a, Decl(intersectionReduction.ts, 25, 15)) + +type X3 = X | { a: string } & undefined; +>X3 : Symbol(X3, Decl(intersectionReduction.ts, 25, 35)) +>X : Symbol(X, Decl(intersectionReduction.ts, 20, 24)) +>a : Symbol(a, Decl(intersectionReduction.ts, 26, 15)) + +type X4 = X | string & number; +>X4 : Symbol(X4, Decl(intersectionReduction.ts, 26, 40)) +>X : Symbol(X, Decl(intersectionReduction.ts, 20, 24)) + +type X5 = X | number & object; +>X5 : Symbol(X5, Decl(intersectionReduction.ts, 27, 30)) +>X : Symbol(X, Decl(intersectionReduction.ts, 20, 24)) + +type X6 = X | symbol & string; +>X6 : Symbol(X6, Decl(intersectionReduction.ts, 28, 30)) +>X : Symbol(X, Decl(intersectionReduction.ts, 20, 24)) + +type X7 = X | void & string; +>X7 : Symbol(X7, Decl(intersectionReduction.ts, 29, 30)) +>X : Symbol(X, Decl(intersectionReduction.ts, 20, 24)) + +// Repro from #31663 + +const x1 = { a: 'foo', b: 42 }; +>x1 : Symbol(x1, Decl(intersectionReduction.ts, 34, 5)) +>a : Symbol(a, Decl(intersectionReduction.ts, 34, 12)) +>b : Symbol(b, Decl(intersectionReduction.ts, 34, 22)) + +const x2 = { a: 'foo', b: true }; +>x2 : Symbol(x2, Decl(intersectionReduction.ts, 35, 5)) +>a : Symbol(a, Decl(intersectionReduction.ts, 35, 12)) +>b : Symbol(b, Decl(intersectionReduction.ts, 35, 22)) + +declare let k: 'a' | 'b'; +>k : Symbol(k, Decl(intersectionReduction.ts, 37, 11)) + +x1[k] = 'bar' as any; // Error +>x1 : Symbol(x1, Decl(intersectionReduction.ts, 34, 5)) +>k : Symbol(k, Decl(intersectionReduction.ts, 37, 11)) + +x2[k] = 'bar' as any; // Error +>x2 : Symbol(x2, Decl(intersectionReduction.ts, 35, 5)) +>k : Symbol(k, Decl(intersectionReduction.ts, 37, 11)) + +const enum Tag1 {} +>Tag1 : Symbol(Tag1, Decl(intersectionReduction.ts, 40, 21)) + +const enum Tag2 {} +>Tag2 : Symbol(Tag2, Decl(intersectionReduction.ts, 42, 18)) + +declare let s1: string & Tag1; +>s1 : Symbol(s1, Decl(intersectionReduction.ts, 45, 11)) +>Tag1 : Symbol(Tag1, Decl(intersectionReduction.ts, 40, 21)) + +declare let s2: string & Tag2; +>s2 : Symbol(s2, Decl(intersectionReduction.ts, 46, 11)) +>Tag2 : Symbol(Tag2, Decl(intersectionReduction.ts, 42, 18)) + +declare let t1: string & Tag1 | undefined; +>t1 : Symbol(t1, Decl(intersectionReduction.ts, 48, 11)) +>Tag1 : Symbol(Tag1, Decl(intersectionReduction.ts, 40, 21)) + +declare let t2: string & Tag2 | undefined; +>t2 : Symbol(t2, Decl(intersectionReduction.ts, 49, 11)) +>Tag2 : Symbol(Tag2, Decl(intersectionReduction.ts, 42, 18)) + +s1 = s2; +>s1 : Symbol(s1, Decl(intersectionReduction.ts, 45, 11)) +>s2 : Symbol(s2, Decl(intersectionReduction.ts, 46, 11)) + +s2 = s1; +>s2 : Symbol(s2, Decl(intersectionReduction.ts, 46, 11)) +>s1 : Symbol(s1, Decl(intersectionReduction.ts, 45, 11)) + +t1 = t2; +>t1 : Symbol(t1, Decl(intersectionReduction.ts, 48, 11)) +>t2 : Symbol(t2, Decl(intersectionReduction.ts, 49, 11)) + +t2 = t1; +>t2 : Symbol(t2, Decl(intersectionReduction.ts, 49, 11)) +>t1 : Symbol(t1, Decl(intersectionReduction.ts, 48, 11)) diff --git a/tests/baselines/reference/intersectionReduction.types b/tests/baselines/reference/intersectionReduction.types index f8c178cfca43f..9dfeea5c0e508 100644 --- a/tests/baselines/reference/intersectionReduction.types +++ b/tests/baselines/reference/intersectionReduction.types @@ -1,6 +1,4 @@ === tests/cases/conformance/types/intersection/intersectionReduction.ts === -// @strict - declare const sym1: unique symbol; >sym1 : unique symbol @@ -10,26 +8,26 @@ declare const sym2: unique symbol; type T1 = string & 'a'; // 'a' >T1 : "a" -type T2 = 'a' & string & 'b'; // 'a' & 'b' ->T2 : T2 +type T2 = 'a' & string & 'b'; // never +>T2 : never type T3 = number & 10; // 10 >T3 : 10 -type T4 = 10 & number & 20; // 10 & 20 ->T4 : T4 +type T4 = 10 & number & 20; // never +>T4 : never type T5 = symbol & typeof sym1; // typeof sym1 >T5 : unique symbol >sym1 : unique symbol -type T6 = typeof sym1 & symbol & typeof sym2; // typeof sym1 & typeof sym2 ->T6 : T6 +type T6 = typeof sym1 & symbol & typeof sym2; // never +>T6 : never >sym1 : unique symbol >sym2 : unique symbol -type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // 'a' & 10 & typeof sym1 ->T7 : T7 +type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never +>T7 : never >sym1 : unique symbol type T10 = string & ('a' | 'b'); // 'a' | 'b' @@ -38,3 +36,130 @@ type T10 = string & ('a' | 'b'); // 'a' | 'b' type T11 = (string | number) & ('a' | 10); // 'a' | 10 >T11 : "a" | 10 +type N1 = 'a' & 'b'; +>N1 : never + +type N2 = { a: string } & null; +>N2 : null +>a : string +>null : null + +type N3 = { a: string } & undefined; +>N3 : undefined +>a : string + +type N4 = string & number; +>N4 : never + +type N5 = number & object; +>N5 : never + +type N6 = symbol & string; +>N6 : never + +type N7 = void & string; +>N7 : never + +type X = { x: string }; +>X : X +>x : string + +type X1 = X | 'a' & 'b'; +>X1 : X + +type X2 = X | { a: string } & null; +>X2 : X +>a : string +>null : null + +type X3 = X | { a: string } & undefined; +>X3 : X +>a : string + +type X4 = X | string & number; +>X4 : X + +type X5 = X | number & object; +>X5 : X + +type X6 = X | symbol & string; +>X6 : X + +type X7 = X | void & string; +>X7 : X + +// Repro from #31663 + +const x1 = { a: 'foo', b: 42 }; +>x1 : { a: string; b: number; } +>{ a: 'foo', b: 42 } : { a: string; b: number; } +>a : string +>'foo' : "foo" +>b : number +>42 : 42 + +const x2 = { a: 'foo', b: true }; +>x2 : { a: string; b: boolean; } +>{ a: 'foo', b: true } : { a: string; b: boolean; } +>a : string +>'foo' : "foo" +>b : boolean +>true : true + +declare let k: 'a' | 'b'; +>k : "a" | "b" + +x1[k] = 'bar' as any; // Error +>x1[k] = 'bar' as any : any +>x1[k] : never +>x1 : { a: string; b: number; } +>k : "a" | "b" +>'bar' as any : any +>'bar' : "bar" + +x2[k] = 'bar' as any; // Error +>x2[k] = 'bar' as any : any +>x2[k] : never +>x2 : { a: string; b: boolean; } +>k : "a" | "b" +>'bar' as any : any +>'bar' : "bar" + +const enum Tag1 {} +>Tag1 : Tag1 + +const enum Tag2 {} +>Tag2 : Tag2 + +declare let s1: string & Tag1; +>s1 : never + +declare let s2: string & Tag2; +>s2 : never + +declare let t1: string & Tag1 | undefined; +>t1 : undefined + +declare let t2: string & Tag2 | undefined; +>t2 : undefined + +s1 = s2; +>s1 = s2 : never +>s1 : never +>s2 : never + +s2 = s1; +>s2 = s1 : never +>s2 : never +>s1 : never + +t1 = t2; +>t1 = t2 : undefined +>t1 : undefined +>t2 : undefined + +t2 = t1; +>t2 = t1 : undefined +>t2 : undefined +>t1 : undefined + diff --git a/tests/baselines/reference/intersectionReductionStrict.errors.txt b/tests/baselines/reference/intersectionReductionStrict.errors.txt new file mode 100644 index 0000000000000..bf174ce04ef60 --- /dev/null +++ b/tests/baselines/reference/intersectionReductionStrict.errors.txt @@ -0,0 +1,66 @@ +tests/cases/conformance/types/intersection/intersectionReductionStrict.ts(40,1): error TS2322: Type 'any' is not assignable to type 'never'. +tests/cases/conformance/types/intersection/intersectionReductionStrict.ts(41,1): error TS2322: Type 'any' is not assignable to type 'never'. + + +==== tests/cases/conformance/types/intersection/intersectionReductionStrict.ts (2 errors) ==== + declare const sym1: unique symbol; + declare const sym2: unique symbol; + + type T1 = string & 'a'; // 'a' + type T2 = 'a' & string & 'b'; // never + type T3 = number & 10; // 10 + type T4 = 10 & number & 20; // never + type T5 = symbol & typeof sym1; // typeof sym1 + type T6 = typeof sym1 & symbol & typeof sym2; // never + type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never + + type T10 = string & ('a' | 'b'); // 'a' | 'b' + type T11 = (string | number) & ('a' | 10); // 'a' | 10 + + type N1 = 'a' & 'b'; + type N2 = { a: string } & null; + type N3 = { a: string } & undefined; + type N4 = string & number; + type N5 = number & object; + type N6 = symbol & string; + type N7 = void & string; + + type X = { x: string }; + + type X1 = X | 'a' & 'b'; + type X2 = X | { a: string } & null; + type X3 = X | { a: string } & undefined; + type X4 = X | string & number; + type X5 = X | number & object; + type X6 = X | symbol & string; + type X7 = X | void & string; + + // Repro from #31663 + + const x1 = { a: 'foo', b: 42 }; + const x2 = { a: 'foo', b: true }; + + declare let k: 'a' | 'b'; + + x1[k] = 'bar' as any; // Error + ~~~~~ +!!! error TS2322: Type 'any' is not assignable to type 'never'. + x2[k] = 'bar' as any; // Error + ~~~~~ +!!! error TS2322: Type 'any' is not assignable to type 'never'. + + const enum Tag1 {} + const enum Tag2 {} + + declare let s1: string & Tag1; + declare let s2: string & Tag2; + + declare let t1: string & Tag1 | undefined; + declare let t2: string & Tag2 | undefined; + + s1 = s2; + s2 = s1; + + t1 = t2; + t2 = t1; + \ No newline at end of file diff --git a/tests/baselines/reference/intersectionReductionStrict.js b/tests/baselines/reference/intersectionReductionStrict.js new file mode 100644 index 0000000000000..32845471a06a2 --- /dev/null +++ b/tests/baselines/reference/intersectionReductionStrict.js @@ -0,0 +1,70 @@ +//// [intersectionReductionStrict.ts] +declare const sym1: unique symbol; +declare const sym2: unique symbol; + +type T1 = string & 'a'; // 'a' +type T2 = 'a' & string & 'b'; // never +type T3 = number & 10; // 10 +type T4 = 10 & number & 20; // never +type T5 = symbol & typeof sym1; // typeof sym1 +type T6 = typeof sym1 & symbol & typeof sym2; // never +type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never + +type T10 = string & ('a' | 'b'); // 'a' | 'b' +type T11 = (string | number) & ('a' | 10); // 'a' | 10 + +type N1 = 'a' & 'b'; +type N2 = { a: string } & null; +type N3 = { a: string } & undefined; +type N4 = string & number; +type N5 = number & object; +type N6 = symbol & string; +type N7 = void & string; + +type X = { x: string }; + +type X1 = X | 'a' & 'b'; +type X2 = X | { a: string } & null; +type X3 = X | { a: string } & undefined; +type X4 = X | string & number; +type X5 = X | number & object; +type X6 = X | symbol & string; +type X7 = X | void & string; + +// Repro from #31663 + +const x1 = { a: 'foo', b: 42 }; +const x2 = { a: 'foo', b: true }; + +declare let k: 'a' | 'b'; + +x1[k] = 'bar' as any; // Error +x2[k] = 'bar' as any; // Error + +const enum Tag1 {} +const enum Tag2 {} + +declare let s1: string & Tag1; +declare let s2: string & Tag2; + +declare let t1: string & Tag1 | undefined; +declare let t2: string & Tag2 | undefined; + +s1 = s2; +s2 = s1; + +t1 = t2; +t2 = t1; + + +//// [intersectionReductionStrict.js] +"use strict"; +// Repro from #31663 +var x1 = { a: 'foo', b: 42 }; +var x2 = { a: 'foo', b: true }; +x1[k] = 'bar'; // Error +x2[k] = 'bar'; // Error +s1 = s2; +s2 = s1; +t1 = t2; +t2 = t1; diff --git a/tests/baselines/reference/intersectionReductionStrict.symbols b/tests/baselines/reference/intersectionReductionStrict.symbols new file mode 100644 index 0000000000000..6e9d7e03a8e04 --- /dev/null +++ b/tests/baselines/reference/intersectionReductionStrict.symbols @@ -0,0 +1,156 @@ +=== tests/cases/conformance/types/intersection/intersectionReductionStrict.ts === +declare const sym1: unique symbol; +>sym1 : Symbol(sym1, Decl(intersectionReductionStrict.ts, 0, 13)) + +declare const sym2: unique symbol; +>sym2 : Symbol(sym2, Decl(intersectionReductionStrict.ts, 1, 13)) + +type T1 = string & 'a'; // 'a' +>T1 : Symbol(T1, Decl(intersectionReductionStrict.ts, 1, 34)) + +type T2 = 'a' & string & 'b'; // never +>T2 : Symbol(T2, Decl(intersectionReductionStrict.ts, 3, 23)) + +type T3 = number & 10; // 10 +>T3 : Symbol(T3, Decl(intersectionReductionStrict.ts, 4, 29)) + +type T4 = 10 & number & 20; // never +>T4 : Symbol(T4, Decl(intersectionReductionStrict.ts, 5, 22)) + +type T5 = symbol & typeof sym1; // typeof sym1 +>T5 : Symbol(T5, Decl(intersectionReductionStrict.ts, 6, 27)) +>sym1 : Symbol(sym1, Decl(intersectionReductionStrict.ts, 0, 13)) + +type T6 = typeof sym1 & symbol & typeof sym2; // never +>T6 : Symbol(T6, Decl(intersectionReductionStrict.ts, 7, 31)) +>sym1 : Symbol(sym1, Decl(intersectionReductionStrict.ts, 0, 13)) +>sym2 : Symbol(sym2, Decl(intersectionReductionStrict.ts, 1, 13)) + +type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never +>T7 : Symbol(T7, Decl(intersectionReductionStrict.ts, 8, 45)) +>sym1 : Symbol(sym1, Decl(intersectionReductionStrict.ts, 0, 13)) + +type T10 = string & ('a' | 'b'); // 'a' | 'b' +>T10 : Symbol(T10, Decl(intersectionReductionStrict.ts, 9, 60)) + +type T11 = (string | number) & ('a' | 10); // 'a' | 10 +>T11 : Symbol(T11, Decl(intersectionReductionStrict.ts, 11, 32)) + +type N1 = 'a' & 'b'; +>N1 : Symbol(N1, Decl(intersectionReductionStrict.ts, 12, 42)) + +type N2 = { a: string } & null; +>N2 : Symbol(N2, Decl(intersectionReductionStrict.ts, 14, 20)) +>a : Symbol(a, Decl(intersectionReductionStrict.ts, 15, 11)) + +type N3 = { a: string } & undefined; +>N3 : Symbol(N3, Decl(intersectionReductionStrict.ts, 15, 31)) +>a : Symbol(a, Decl(intersectionReductionStrict.ts, 16, 11)) + +type N4 = string & number; +>N4 : Symbol(N4, Decl(intersectionReductionStrict.ts, 16, 36)) + +type N5 = number & object; +>N5 : Symbol(N5, Decl(intersectionReductionStrict.ts, 17, 26)) + +type N6 = symbol & string; +>N6 : Symbol(N6, Decl(intersectionReductionStrict.ts, 18, 26)) + +type N7 = void & string; +>N7 : Symbol(N7, Decl(intersectionReductionStrict.ts, 19, 26)) + +type X = { x: string }; +>X : Symbol(X, Decl(intersectionReductionStrict.ts, 20, 24)) +>x : Symbol(x, Decl(intersectionReductionStrict.ts, 22, 10)) + +type X1 = X | 'a' & 'b'; +>X1 : Symbol(X1, Decl(intersectionReductionStrict.ts, 22, 23)) +>X : Symbol(X, Decl(intersectionReductionStrict.ts, 20, 24)) + +type X2 = X | { a: string } & null; +>X2 : Symbol(X2, Decl(intersectionReductionStrict.ts, 24, 24)) +>X : Symbol(X, Decl(intersectionReductionStrict.ts, 20, 24)) +>a : Symbol(a, Decl(intersectionReductionStrict.ts, 25, 15)) + +type X3 = X | { a: string } & undefined; +>X3 : Symbol(X3, Decl(intersectionReductionStrict.ts, 25, 35)) +>X : Symbol(X, Decl(intersectionReductionStrict.ts, 20, 24)) +>a : Symbol(a, Decl(intersectionReductionStrict.ts, 26, 15)) + +type X4 = X | string & number; +>X4 : Symbol(X4, Decl(intersectionReductionStrict.ts, 26, 40)) +>X : Symbol(X, Decl(intersectionReductionStrict.ts, 20, 24)) + +type X5 = X | number & object; +>X5 : Symbol(X5, Decl(intersectionReductionStrict.ts, 27, 30)) +>X : Symbol(X, Decl(intersectionReductionStrict.ts, 20, 24)) + +type X6 = X | symbol & string; +>X6 : Symbol(X6, Decl(intersectionReductionStrict.ts, 28, 30)) +>X : Symbol(X, Decl(intersectionReductionStrict.ts, 20, 24)) + +type X7 = X | void & string; +>X7 : Symbol(X7, Decl(intersectionReductionStrict.ts, 29, 30)) +>X : Symbol(X, Decl(intersectionReductionStrict.ts, 20, 24)) + +// Repro from #31663 + +const x1 = { a: 'foo', b: 42 }; +>x1 : Symbol(x1, Decl(intersectionReductionStrict.ts, 34, 5)) +>a : Symbol(a, Decl(intersectionReductionStrict.ts, 34, 12)) +>b : Symbol(b, Decl(intersectionReductionStrict.ts, 34, 22)) + +const x2 = { a: 'foo', b: true }; +>x2 : Symbol(x2, Decl(intersectionReductionStrict.ts, 35, 5)) +>a : Symbol(a, Decl(intersectionReductionStrict.ts, 35, 12)) +>b : Symbol(b, Decl(intersectionReductionStrict.ts, 35, 22)) + +declare let k: 'a' | 'b'; +>k : Symbol(k, Decl(intersectionReductionStrict.ts, 37, 11)) + +x1[k] = 'bar' as any; // Error +>x1 : Symbol(x1, Decl(intersectionReductionStrict.ts, 34, 5)) +>k : Symbol(k, Decl(intersectionReductionStrict.ts, 37, 11)) + +x2[k] = 'bar' as any; // Error +>x2 : Symbol(x2, Decl(intersectionReductionStrict.ts, 35, 5)) +>k : Symbol(k, Decl(intersectionReductionStrict.ts, 37, 11)) + +const enum Tag1 {} +>Tag1 : Symbol(Tag1, Decl(intersectionReductionStrict.ts, 40, 21)) + +const enum Tag2 {} +>Tag2 : Symbol(Tag2, Decl(intersectionReductionStrict.ts, 42, 18)) + +declare let s1: string & Tag1; +>s1 : Symbol(s1, Decl(intersectionReductionStrict.ts, 45, 11)) +>Tag1 : Symbol(Tag1, Decl(intersectionReductionStrict.ts, 40, 21)) + +declare let s2: string & Tag2; +>s2 : Symbol(s2, Decl(intersectionReductionStrict.ts, 46, 11)) +>Tag2 : Symbol(Tag2, Decl(intersectionReductionStrict.ts, 42, 18)) + +declare let t1: string & Tag1 | undefined; +>t1 : Symbol(t1, Decl(intersectionReductionStrict.ts, 48, 11)) +>Tag1 : Symbol(Tag1, Decl(intersectionReductionStrict.ts, 40, 21)) + +declare let t2: string & Tag2 | undefined; +>t2 : Symbol(t2, Decl(intersectionReductionStrict.ts, 49, 11)) +>Tag2 : Symbol(Tag2, Decl(intersectionReductionStrict.ts, 42, 18)) + +s1 = s2; +>s1 : Symbol(s1, Decl(intersectionReductionStrict.ts, 45, 11)) +>s2 : Symbol(s2, Decl(intersectionReductionStrict.ts, 46, 11)) + +s2 = s1; +>s2 : Symbol(s2, Decl(intersectionReductionStrict.ts, 46, 11)) +>s1 : Symbol(s1, Decl(intersectionReductionStrict.ts, 45, 11)) + +t1 = t2; +>t1 : Symbol(t1, Decl(intersectionReductionStrict.ts, 48, 11)) +>t2 : Symbol(t2, Decl(intersectionReductionStrict.ts, 49, 11)) + +t2 = t1; +>t2 : Symbol(t2, Decl(intersectionReductionStrict.ts, 49, 11)) +>t1 : Symbol(t1, Decl(intersectionReductionStrict.ts, 48, 11)) + diff --git a/tests/baselines/reference/intersectionReductionStrict.types b/tests/baselines/reference/intersectionReductionStrict.types new file mode 100644 index 0000000000000..8227f6b407259 --- /dev/null +++ b/tests/baselines/reference/intersectionReductionStrict.types @@ -0,0 +1,165 @@ +=== tests/cases/conformance/types/intersection/intersectionReductionStrict.ts === +declare const sym1: unique symbol; +>sym1 : unique symbol + +declare const sym2: unique symbol; +>sym2 : unique symbol + +type T1 = string & 'a'; // 'a' +>T1 : "a" + +type T2 = 'a' & string & 'b'; // never +>T2 : never + +type T3 = number & 10; // 10 +>T3 : 10 + +type T4 = 10 & number & 20; // never +>T4 : never + +type T5 = symbol & typeof sym1; // typeof sym1 +>T5 : unique symbol +>sym1 : unique symbol + +type T6 = typeof sym1 & symbol & typeof sym2; // never +>T6 : never +>sym1 : unique symbol +>sym2 : unique symbol + +type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never +>T7 : never +>sym1 : unique symbol + +type T10 = string & ('a' | 'b'); // 'a' | 'b' +>T10 : "a" | "b" + +type T11 = (string | number) & ('a' | 10); // 'a' | 10 +>T11 : "a" | 10 + +type N1 = 'a' & 'b'; +>N1 : never + +type N2 = { a: string } & null; +>N2 : never +>a : string +>null : null + +type N3 = { a: string } & undefined; +>N3 : never +>a : string + +type N4 = string & number; +>N4 : never + +type N5 = number & object; +>N5 : never + +type N6 = symbol & string; +>N6 : never + +type N7 = void & string; +>N7 : never + +type X = { x: string }; +>X : X +>x : string + +type X1 = X | 'a' & 'b'; +>X1 : X + +type X2 = X | { a: string } & null; +>X2 : X +>a : string +>null : null + +type X3 = X | { a: string } & undefined; +>X3 : X +>a : string + +type X4 = X | string & number; +>X4 : X + +type X5 = X | number & object; +>X5 : X + +type X6 = X | symbol & string; +>X6 : X + +type X7 = X | void & string; +>X7 : X + +// Repro from #31663 + +const x1 = { a: 'foo', b: 42 }; +>x1 : { a: string; b: number; } +>{ a: 'foo', b: 42 } : { a: string; b: number; } +>a : string +>'foo' : "foo" +>b : number +>42 : 42 + +const x2 = { a: 'foo', b: true }; +>x2 : { a: string; b: boolean; } +>{ a: 'foo', b: true } : { a: string; b: boolean; } +>a : string +>'foo' : "foo" +>b : boolean +>true : true + +declare let k: 'a' | 'b'; +>k : "a" | "b" + +x1[k] = 'bar' as any; // Error +>x1[k] = 'bar' as any : any +>x1[k] : never +>x1 : { a: string; b: number; } +>k : "a" | "b" +>'bar' as any : any +>'bar' : "bar" + +x2[k] = 'bar' as any; // Error +>x2[k] = 'bar' as any : any +>x2[k] : never +>x2 : { a: string; b: boolean; } +>k : "a" | "b" +>'bar' as any : any +>'bar' : "bar" + +const enum Tag1 {} +>Tag1 : Tag1 + +const enum Tag2 {} +>Tag2 : Tag2 + +declare let s1: string & Tag1; +>s1 : never + +declare let s2: string & Tag2; +>s2 : never + +declare let t1: string & Tag1 | undefined; +>t1 : undefined + +declare let t2: string & Tag2 | undefined; +>t2 : undefined + +s1 = s2; +>s1 = s2 : never +>s1 : never +>s2 : never + +s2 = s1; +>s2 = s1 : never +>s2 : never +>s1 : never + +t1 = t2; +>t1 = t2 : undefined +>t1 : undefined +>t2 : undefined + +t2 = t1; +>t2 = t1 : undefined +>t2 : undefined +>t1 : undefined + diff --git a/tests/baselines/reference/intersectionTypeInference2.js b/tests/baselines/reference/intersectionTypeInference2.js index 804b8d8520600..806af6872d766 100644 --- a/tests/baselines/reference/intersectionTypeInference2.js +++ b/tests/baselines/reference/intersectionTypeInference2.js @@ -4,8 +4,8 @@ declare function f(x: { prop: T }): T; declare const a: { prop: string } & { prop: number }; declare const b: { prop: string & number }; -f(a); // string & number -f(b); // string & number +f(a); // never +f(b); // never // Repro from #18354 @@ -17,7 +17,7 @@ f2(obj, 'b'); //// [intersectionTypeInference2.js] -f(a); // string & number -f(b); // string & number +f(a); // never +f(b); // never f2(obj, 'a'); f2(obj, 'b'); diff --git a/tests/baselines/reference/intersectionTypeInference2.symbols b/tests/baselines/reference/intersectionTypeInference2.symbols index b04de204de183..20b7d0b1d4cf8 100644 --- a/tests/baselines/reference/intersectionTypeInference2.symbols +++ b/tests/baselines/reference/intersectionTypeInference2.symbols @@ -16,11 +16,11 @@ declare const b: { prop: string & number }; >b : Symbol(b, Decl(intersectionTypeInference2.ts, 3, 13)) >prop : Symbol(prop, Decl(intersectionTypeInference2.ts, 3, 18)) -f(a); // string & number +f(a); // never >f : Symbol(f, Decl(intersectionTypeInference2.ts, 0, 0)) >a : Symbol(a, Decl(intersectionTypeInference2.ts, 2, 13)) -f(b); // string & number +f(b); // never >f : Symbol(f, Decl(intersectionTypeInference2.ts, 0, 0)) >b : Symbol(b, Decl(intersectionTypeInference2.ts, 3, 13)) diff --git a/tests/baselines/reference/intersectionTypeInference2.types b/tests/baselines/reference/intersectionTypeInference2.types index 72f4bf30e1f7a..d34b8545a9f33 100644 --- a/tests/baselines/reference/intersectionTypeInference2.types +++ b/tests/baselines/reference/intersectionTypeInference2.types @@ -10,18 +10,18 @@ declare const a: { prop: string } & { prop: number }; >prop : number declare const b: { prop: string & number }; ->b : { prop: string & number; } ->prop : string & number +>b : { prop: never; } +>prop : never -f(a); // string & number ->f(a) : string & number +f(a); // never +>f(a) : never >f : (x: { prop: T; }) => T >a : { prop: string; } & { prop: number; } -f(b); // string & number ->f(b) : string & number +f(b); // never +>f(b) : never >f : (x: { prop: T; }) => T ->b : { prop: string & number; } +>b : { prop: never; } // Repro from #18354 diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js index c79ae58ae41ff..e56ad3d5434da 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.js +++ b/tests/baselines/reference/keyofAndIndexedAccess.js @@ -672,6 +672,13 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; var Shape = /** @class */ (function () { function Shape() { } @@ -951,7 +958,7 @@ function f1(thing) { var x1 = path(thing, 'a'); // { x: number, y: string } var x2 = path(thing, 'a', 'y'); // string var x3 = path(thing, 'b'); // boolean - var x4 = path.apply(void 0, [thing].concat(['a', 'x'])); // any + var x4 = path.apply(void 0, __spreadArrays([thing], ['a', 'x'])); // any } // Repro from comment in #12114 var assignTo2 = function (object, key1, key2) { diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt b/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt index fffeac41ff7b5..ff96efe3e13fc 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt @@ -17,8 +17,7 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(31,5): error TS232 tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(38,5): error TS2322: Type '{ [x: string]: number; }' is not assignable to type '{ [P in K]: number; }'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(50,3): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Item'. No index signature with a parameter of type 'string' was found on type 'Item'. -tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(51,3): error TS2322: Type '123' is not assignable to type 'string & number'. - Type '123' is not assignable to type 'string'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(51,3): error TS2322: Type '123' is not assignable to type 'never'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(52,3): error TS2322: Type '123' is not assignable to type 'T[keyof T]'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(53,3): error TS2322: Type '123' is not assignable to type 'T[K]'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(65,7): error TS2339: Property 'foo' does not exist on type 'T'. @@ -26,8 +25,7 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(66,3): error TS253 tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(67,3): error TS2322: Type '123' is not assignable to type 'T[keyof T]'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(68,3): error TS2322: Type '123' is not assignable to type 'T[K]'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(108,5): error TS2322: Type '123' is not assignable to type 'Type[K]'. - Type '123' is not assignable to type '123 & "some string"'. - Type '123' is not assignable to type '"some string"'. + Type '123' is not assignable to type 'never'. ==== tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts (23 errors) ==== @@ -117,8 +115,7 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(108,5): error TS23 !!! error TS7053: No index signature with a parameter of type 'string' was found on type 'Item'. obj[k2] = 123; // Error ~~~~~~~ -!!! error TS2322: Type '123' is not assignable to type 'string & number'. -!!! error TS2322: Type '123' is not assignable to type 'string'. +!!! error TS2322: Type '123' is not assignable to type 'never'. obj[k3] = 123; // Error ~~~~~~~ !!! error TS2322: Type '123' is not assignable to type 'T[keyof T]'. @@ -190,8 +187,7 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(108,5): error TS23 return 123; // Error ~~~~~~~~~~~ !!! error TS2322: Type '123' is not assignable to type 'Type[K]'. -!!! error TS2322: Type '123' is not assignable to type '123 & "some string"'. -!!! error TS2322: Type '123' is not assignable to type '"some string"'. +!!! error TS2322: Type '123' is not assignable to type 'never'. } // Repro from #30920 diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.types b/tests/baselines/reference/keyofAndIndexedAccess2.types index a6d8315466562..b282588cc5159 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.types +++ b/tests/baselines/reference/keyofAndIndexedAccess2.types @@ -249,7 +249,7 @@ function f10(obj: T, k1: string, k2: keyof It obj[k2] = 123; // Error >obj[k2] = 123 : 123 ->obj[k2] : string & number +>obj[k2] : never >obj : T >k2 : "a" | "b" >123 : 123 diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt index 68e56efb38ab9..69f992447e8b3 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt @@ -10,7 +10,6 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(27,18): error tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(28,18): error TS2538: Type '{ x: string; }' cannot be used as an index type. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(29,18): error TS2537: Type 'Shape' has no matching index signature for type 'number'. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(29,18): error TS2537: Type 'Shape' has no matching index signature for type 'string'. -tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(30,18): error TS2538: Type 'string & number' cannot be used as an index type. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(31,18): error TS2537: Type 'Shape' has no matching index signature for type 'string'. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(31,18): error TS2538: Type 'false' cannot be used as an index type. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(31,18): error TS2538: Type 'true' cannot be used as an index type. @@ -81,7 +80,7 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(141,5): error tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(142,5): error TS2322: Type 'number[]' is not assignable to type 'T[K]'. -==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (41 errors) ==== +==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (40 errors) ==== class Shape { name: string; width: number; @@ -135,9 +134,7 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(142,5): error !!! error TS2537: Type 'Shape' has no matching index signature for type 'number'. ~~~~~~~~~~~~~~~ !!! error TS2537: Type 'Shape' has no matching index signature for type 'string'. - type T21 = Shape[string & number]; // Error - ~~~~~~~~~~~~~~~ -!!! error TS2538: Type 'string & number' cannot be used as an index type. + type T21 = Shape[string & number]; type T22 = Shape[string | boolean]; // Error ~~~~~~~~~~~~~~~~ !!! error TS2537: Type 'Shape' has no matching index signature for type 'string'. diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.js b/tests/baselines/reference/keyofAndIndexedAccessErrors.js index f262f9a0d3c67..864cd0731ac52 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.js +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.js @@ -28,7 +28,7 @@ type T17 = Shape[void]; // Error type T18 = Shape[undefined]; // Error type T19 = Shape[{ x: string }]; // Error type T20 = Shape[string | number]; // Error -type T21 = Shape[string & number]; // Error +type T21 = Shape[string & number]; type T22 = Shape[string | boolean]; // Error type T30 = string[]["length"]; diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols b/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols index 1dd7c0d564828..3c11ae4d744fe 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols @@ -93,7 +93,7 @@ type T20 = Shape[string | number]; // Error >T20 : Symbol(T20, Decl(keyofAndIndexedAccessErrors.ts, 27, 32)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccessErrors.ts, 0, 0)) -type T21 = Shape[string & number]; // Error +type T21 = Shape[string & number]; >T21 : Symbol(T21, Decl(keyofAndIndexedAccessErrors.ts, 28, 34)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccessErrors.ts, 0, 0)) diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.types b/tests/baselines/reference/keyofAndIndexedAccessErrors.types index 780138d6c6bcd..90d2c462d0a69 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.types +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.types @@ -74,8 +74,8 @@ type T19 = Shape[{ x: string }]; // Error type T20 = Shape[string | number]; // Error >T20 : any -type T21 = Shape[string & number]; // Error ->T21 : any +type T21 = Shape[string & number]; +>T21 : never type T22 = Shape[string | boolean]; // Error >T22 : any diff --git a/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.js b/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.js index a4ab83607cfb6..48748b2b5828a 100644 --- a/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.js +++ b/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.js @@ -62,6 +62,13 @@ function f5() { } //// [literalFreshnessPropagationOnNarrowing.js] +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; function f1() { var b = true; var obj = { b: b }; @@ -83,7 +90,7 @@ function f2() { // Desired: OK // 3.0: Error // 3.1: OK - var a5 = (Array.isArray(elOrA) ? elOrA : [elOrA]).slice(); + var a5 = __spreadArrays(Array.isArray(elOrA) ? elOrA : [elOrA]); } function f3() { var x = 'x'; diff --git a/tests/baselines/reference/newWithSpread.js b/tests/baselines/reference/newWithSpread.js index dec46394b21bd..56a51291a8cb6 100644 --- a/tests/baselines/reference/newWithSpread.js +++ b/tests/baselines/reference/newWithSpread.js @@ -97,6 +97,13 @@ new i["a-b"][1](1, 2, ...a); new i["a-b"][1](1, 2, ...a, "string"); //// [newWithSpread.js] +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t; function f(x, y) { var z = []; @@ -129,52 +136,52 @@ var h; var i; // Basic expression new f(1, 2, "string"); -new (f.bind.apply(f, [void 0, 1, 2].concat(a)))(); -new (f.bind.apply(f, [void 0, 1, 2].concat(a, ["string"])))(); +new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a)))(); +new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Multiple spreads arguments -new (f2.bind.apply(f2, [void 0].concat(a, a)))(); -new (f.bind.apply(f, [void 0, 1, 2].concat(a, a)))(); +new (f2.bind.apply(f2, __spreadArrays([void 0], a, a)))(); +new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a, a)))(); // Call expression new f(1, 2, "string")(); -new (f.bind.apply(f, [void 0, 1, 2].concat(a)))()(); -new (f.bind.apply(f, [void 0, 1, 2].concat(a, ["string"])))()(); +new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a)))()(); +new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a, ["string"])))()(); // Property access expression new b.f(1, 2, "string"); -new ((_a = b.f).bind.apply(_a, [void 0, 1, 2].concat(a)))(); -new ((_b = b.f).bind.apply(_b, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_a = b.f).bind.apply(_a, __spreadArrays([void 0, 1, 2], a)))(); +new ((_b = b.f).bind.apply(_b, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Parenthesised expression new (b.f)(1, 2, "string"); -new ((_c = (b.f)).bind.apply(_c, [void 0, 1, 2].concat(a)))(); -new ((_d = (b.f)).bind.apply(_d, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_c = (b.f)).bind.apply(_c, __spreadArrays([void 0, 1, 2], a)))(); +new ((_d = (b.f)).bind.apply(_d, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Element access expression new d[1].f(1, 2, "string"); -new ((_e = d[1].f).bind.apply(_e, [void 0, 1, 2].concat(a)))(); -new ((_f = d[1].f).bind.apply(_f, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_e = d[1].f).bind.apply(_e, __spreadArrays([void 0, 1, 2], a)))(); +new ((_f = d[1].f).bind.apply(_f, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Element access expression with a punctuated key new e["a-b"].f(1, 2, "string"); -new ((_g = e["a-b"].f).bind.apply(_g, [void 0, 1, 2].concat(a)))(); -new ((_h = e["a-b"].f).bind.apply(_h, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_g = e["a-b"].f).bind.apply(_g, __spreadArrays([void 0, 1, 2], a)))(); +new ((_h = e["a-b"].f).bind.apply(_h, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Basic expression new B(1, 2, "string"); -new (B.bind.apply(B, [void 0, 1, 2].concat(a)))(); -new (B.bind.apply(B, [void 0, 1, 2].concat(a, ["string"])))(); +new (B.bind.apply(B, __spreadArrays([void 0, 1, 2], a)))(); +new (B.bind.apply(B, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Property access expression new c["a-b"](1, 2, "string"); -new ((_j = c["a-b"]).bind.apply(_j, [void 0, 1, 2].concat(a)))(); -new ((_k = c["a-b"]).bind.apply(_k, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_j = c["a-b"]).bind.apply(_j, __spreadArrays([void 0, 1, 2], a)))(); +new ((_k = c["a-b"]).bind.apply(_k, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Parenthesised expression new (c["a-b"])(1, 2, "string"); -new ((_l = (c["a-b"])).bind.apply(_l, [void 0, 1, 2].concat(a)))(); -new ((_m = (c["a-b"])).bind.apply(_m, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_l = (c["a-b"])).bind.apply(_l, __spreadArrays([void 0, 1, 2], a)))(); +new ((_m = (c["a-b"])).bind.apply(_m, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Element access expression new g[1]["a-b"](1, 2, "string"); -new ((_o = g[1]["a-b"]).bind.apply(_o, [void 0, 1, 2].concat(a)))(); -new ((_p = g[1]["a-b"]).bind.apply(_p, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_o = g[1]["a-b"]).bind.apply(_o, __spreadArrays([void 0, 1, 2], a)))(); +new ((_p = g[1]["a-b"]).bind.apply(_p, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Element access expression with a punctuated key new h["a-b"]["a-b"](1, 2, "string"); -new ((_q = h["a-b"]["a-b"]).bind.apply(_q, [void 0, 1, 2].concat(a)))(); -new ((_r = h["a-b"]["a-b"]).bind.apply(_r, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_q = h["a-b"]["a-b"]).bind.apply(_q, __spreadArrays([void 0, 1, 2], a)))(); +new ((_r = h["a-b"]["a-b"]).bind.apply(_r, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Element access expression with a number new i["a-b"][1](1, 2, "string"); -new ((_s = i["a-b"][1]).bind.apply(_s, [void 0, 1, 2].concat(a)))(); -new ((_t = i["a-b"][1]).bind.apply(_t, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_s = i["a-b"][1]).bind.apply(_s, __spreadArrays([void 0, 1, 2], a)))(); +new ((_t = i["a-b"][1]).bind.apply(_t, __spreadArrays([void 0, 1, 2], a, ["string"])))(); diff --git a/tests/baselines/reference/newWithSpreadES5.js b/tests/baselines/reference/newWithSpreadES5.js index 13e2ffe6d6ad5..ddb219a498732 100644 --- a/tests/baselines/reference/newWithSpreadES5.js +++ b/tests/baselines/reference/newWithSpreadES5.js @@ -96,6 +96,13 @@ new i["a-b"][1](1, 2, ...a); new i["a-b"][1](1, 2, ...a, "string"); //// [newWithSpreadES5.js] +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t; function f(x, y) { var z = []; @@ -128,52 +135,52 @@ var h; var i; // Basic expression new f(1, 2, "string"); -new (f.bind.apply(f, [void 0, 1, 2].concat(a)))(); -new (f.bind.apply(f, [void 0, 1, 2].concat(a, ["string"])))(); +new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a)))(); +new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Multiple spreads arguments -new (f2.bind.apply(f2, [void 0].concat(a, a)))(); -new (f.bind.apply(f, [void 0, 1, 2].concat(a, a)))(); +new (f2.bind.apply(f2, __spreadArrays([void 0], a, a)))(); +new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a, a)))(); // Call expression new f(1, 2, "string")(); -new (f.bind.apply(f, [void 0, 1, 2].concat(a)))()(); -new (f.bind.apply(f, [void 0, 1, 2].concat(a, ["string"])))()(); +new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a)))()(); +new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a, ["string"])))()(); // Property access expression new b.f(1, 2, "string"); -new ((_a = b.f).bind.apply(_a, [void 0, 1, 2].concat(a)))(); -new ((_b = b.f).bind.apply(_b, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_a = b.f).bind.apply(_a, __spreadArrays([void 0, 1, 2], a)))(); +new ((_b = b.f).bind.apply(_b, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Parenthesised expression new (b.f)(1, 2, "string"); -new ((_c = (b.f)).bind.apply(_c, [void 0, 1, 2].concat(a)))(); -new ((_d = (b.f)).bind.apply(_d, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_c = (b.f)).bind.apply(_c, __spreadArrays([void 0, 1, 2], a)))(); +new ((_d = (b.f)).bind.apply(_d, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Element access expression new d[1].f(1, 2, "string"); -new ((_e = d[1].f).bind.apply(_e, [void 0, 1, 2].concat(a)))(); -new ((_f = d[1].f).bind.apply(_f, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_e = d[1].f).bind.apply(_e, __spreadArrays([void 0, 1, 2], a)))(); +new ((_f = d[1].f).bind.apply(_f, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Element access expression with a punctuated key new e["a-b"].f(1, 2, "string"); -new ((_g = e["a-b"].f).bind.apply(_g, [void 0, 1, 2].concat(a)))(); -new ((_h = e["a-b"].f).bind.apply(_h, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_g = e["a-b"].f).bind.apply(_g, __spreadArrays([void 0, 1, 2], a)))(); +new ((_h = e["a-b"].f).bind.apply(_h, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Basic expression new B(1, 2, "string"); -new (B.bind.apply(B, [void 0, 1, 2].concat(a)))(); -new (B.bind.apply(B, [void 0, 1, 2].concat(a, ["string"])))(); +new (B.bind.apply(B, __spreadArrays([void 0, 1, 2], a)))(); +new (B.bind.apply(B, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Property access expression new c["a-b"](1, 2, "string"); -new ((_j = c["a-b"]).bind.apply(_j, [void 0, 1, 2].concat(a)))(); -new ((_k = c["a-b"]).bind.apply(_k, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_j = c["a-b"]).bind.apply(_j, __spreadArrays([void 0, 1, 2], a)))(); +new ((_k = c["a-b"]).bind.apply(_k, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Parenthesised expression new (c["a-b"])(1, 2, "string"); -new ((_l = (c["a-b"])).bind.apply(_l, [void 0, 1, 2].concat(a)))(); -new ((_m = (c["a-b"])).bind.apply(_m, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_l = (c["a-b"])).bind.apply(_l, __spreadArrays([void 0, 1, 2], a)))(); +new ((_m = (c["a-b"])).bind.apply(_m, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Element access expression new g[1]["a-b"](1, 2, "string"); -new ((_o = g[1]["a-b"]).bind.apply(_o, [void 0, 1, 2].concat(a)))(); -new ((_p = g[1]["a-b"]).bind.apply(_p, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_o = g[1]["a-b"]).bind.apply(_o, __spreadArrays([void 0, 1, 2], a)))(); +new ((_p = g[1]["a-b"]).bind.apply(_p, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Element access expression with a punctuated key new h["a-b"]["a-b"](1, 2, "string"); -new ((_q = h["a-b"]["a-b"]).bind.apply(_q, [void 0, 1, 2].concat(a)))(); -new ((_r = h["a-b"]["a-b"]).bind.apply(_r, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_q = h["a-b"]["a-b"]).bind.apply(_q, __spreadArrays([void 0, 1, 2], a)))(); +new ((_r = h["a-b"]["a-b"]).bind.apply(_r, __spreadArrays([void 0, 1, 2], a, ["string"])))(); // Element access expression with a number new i["a-b"][1](1, 2, "string"); -new ((_s = i["a-b"][1]).bind.apply(_s, [void 0, 1, 2].concat(a)))(); -new ((_t = i["a-b"][1]).bind.apply(_t, [void 0, 1, 2].concat(a, ["string"])))(); +new ((_s = i["a-b"][1]).bind.apply(_s, __spreadArrays([void 0, 1, 2], a)))(); +new ((_t = i["a-b"][1]).bind.apply(_t, __spreadArrays([void 0, 1, 2], a, ["string"])))(); diff --git a/tests/baselines/reference/noCrashOnNoLib.js b/tests/baselines/reference/noCrashOnNoLib.js index 715050103fbe7..a9a1d3930de1c 100644 --- a/tests/baselines/reference/noCrashOnNoLib.js +++ b/tests/baselines/reference/noCrashOnNoLib.js @@ -8,11 +8,18 @@ export function f() { //// [noCrashOnNoLib.js] "use strict"; +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; exports.__esModule = true; function f() { var e; while (true) { - e = (e || []).slice(); + e = __spreadArrays((e || [])); } } exports.f = f; diff --git a/tests/baselines/reference/nonPrimitiveUnionIntersection.errors.txt b/tests/baselines/reference/nonPrimitiveUnionIntersection.errors.txt index 5aad982dc20f0..38bff6c43198a 100644 --- a/tests/baselines/reference/nonPrimitiveUnionIntersection.errors.txt +++ b/tests/baselines/reference/nonPrimitiveUnionIntersection.errors.txt @@ -1,9 +1,7 @@ -tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(1,5): error TS2322: Type '""' is not assignable to type 'object & string'. - Type '""' is not assignable to type 'object'. +tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(1,5): error TS2322: Type '""' is not assignable to type 'never'. tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(3,5): error TS2322: Type '123' is not assignable to type 'object & {}'. Type '123' is not assignable to type 'object'. -tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(4,1): error TS2322: Type 'string' is not assignable to type 'object & string'. - Type 'string' is not assignable to type 'object'. +tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(4,1): error TS2322: Type 'string' is not assignable to type 'never'. tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(8,38): error TS2322: Type '{ bar: string; }' is not assignable to type 'object & { err: string; }'. Object literal may only specify known properties, and 'bar' does not exist in type 'object & { err: string; }'. @@ -11,8 +9,7 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(8,38 ==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts (4 errors) ==== var a: object & string = ""; // error ~ -!!! error TS2322: Type '""' is not assignable to type 'object & string'. -!!! error TS2322: Type '""' is not assignable to type 'object'. +!!! error TS2322: Type '""' is not assignable to type 'never'. var b: object | string = ""; // ok var c: object & {} = 123; // error ~ @@ -20,8 +17,7 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(8,38 !!! error TS2322: Type '123' is not assignable to type 'object'. a = b; // error ~ -!!! error TS2322: Type 'string' is not assignable to type 'object & string'. -!!! error TS2322: Type 'string' is not assignable to type 'object'. +!!! error TS2322: Type 'string' is not assignable to type 'never'. b = a; // ok const foo: object & {} = {bar: 'bar'}; // ok diff --git a/tests/baselines/reference/nonPrimitiveUnionIntersection.types b/tests/baselines/reference/nonPrimitiveUnionIntersection.types index 55a0b2a018c22..ef7e2f8928b93 100644 --- a/tests/baselines/reference/nonPrimitiveUnionIntersection.types +++ b/tests/baselines/reference/nonPrimitiveUnionIntersection.types @@ -1,6 +1,6 @@ === tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts === var a: object & string = ""; // error ->a : object & string +>a : never >"" : "" var b: object | string = ""; // ok @@ -13,13 +13,13 @@ var c: object & {} = 123; // error a = b; // error >a = b : string ->a : object & string +>a : never >b : string b = a; // ok ->b = a : object & string +>b = a : never >b : string | object ->a : object & string +>a : never const foo: object & {} = {bar: 'bar'}; // ok >foo : object & {} diff --git a/tests/baselines/reference/readonlyRestParameters.js b/tests/baselines/reference/readonlyRestParameters.js index f6ccaf6081de4..35c07df1c452c 100644 --- a/tests/baselines/reference/readonlyRestParameters.js +++ b/tests/baselines/reference/readonlyRestParameters.js @@ -29,6 +29,13 @@ function f4(...args: readonly string[]) { //// [readonlyRestParameters.js] "use strict"; +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; function f0(a, b) { f0(a, b); f1(a, b); @@ -41,7 +48,7 @@ function f1() { } f0.apply(void 0, args); // Error f1('abc', 'def'); - f1.apply(void 0, ['abc'].concat(args)); + f1.apply(void 0, __spreadArrays(['abc'], args)); f1.apply(void 0, args); } function f2() { @@ -51,10 +58,10 @@ function f2() { } f0.apply(void 0, args); f1('abc', 'def'); - f1.apply(void 0, ['abc'].concat(args)); + f1.apply(void 0, __spreadArrays(['abc'], args)); f1.apply(void 0, args); f2('abc', 'def'); - f2.apply(void 0, ['abc'].concat(args)); // Error + f2.apply(void 0, __spreadArrays(['abc'], args)); // Error f2.apply(void 0, args); } function f4() { diff --git a/tests/baselines/reference/restTuplesFromContextualTypes.js b/tests/baselines/reference/restTuplesFromContextualTypes.js index affe55603bf5e..c09274862b803 100644 --- a/tests/baselines/reference/restTuplesFromContextualTypes.js +++ b/tests/baselines/reference/restTuplesFromContextualTypes.js @@ -101,6 +101,13 @@ const funcUnionTupleRest: TupleUnionFunc = (...params) => { //// [restTuplesFromContextualTypes.js] "use strict"; +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; (function (a, b, c) { }).apply(void 0, t1); (function () { var x = []; @@ -201,31 +208,31 @@ f2(function (a, b, c) { x[_i - 3] = arguments[_i]; } }); -(function (a, b, c) { }).apply(void 0, [1].concat(t3)); +(function (a, b, c) { }).apply(void 0, __spreadArrays([1], t3)); (function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { x[_i] = arguments[_i]; } -}).apply(void 0, [1].concat(t3)); +}).apply(void 0, __spreadArrays([1], t3)); (function (a) { var x = []; for (var _i = 1; _i < arguments.length; _i++) { x[_i - 1] = arguments[_i]; } -}).apply(void 0, [1].concat(t3)); +}).apply(void 0, __spreadArrays([1], t3)); (function (a, b) { var x = []; for (var _i = 2; _i < arguments.length; _i++) { x[_i - 2] = arguments[_i]; } -}).apply(void 0, [1].concat(t3)); +}).apply(void 0, __spreadArrays([1], t3)); (function (a, b, c) { var x = []; for (var _i = 3; _i < arguments.length; _i++) { x[_i - 3] = arguments[_i]; } -}).apply(void 0, [1].concat(t3)); +}).apply(void 0, __spreadArrays([1], t3)); f3(function (a, b, c) { }); f3(function () { var x = []; @@ -263,13 +270,13 @@ function f4(t) { for (var _i = 1; _i < arguments.length; _i++) { x[_i - 1] = arguments[_i]; } - }).apply(void 0, [1].concat(t)); + }).apply(void 0, __spreadArrays([1], t)); (function (a) { var x = []; for (var _i = 1; _i < arguments.length; _i++) { x[_i - 1] = arguments[_i]; } - }).apply(void 0, [1, 2].concat(t)); + }).apply(void 0, __spreadArrays([1, 2], t)); function f(cb) { } f(function () { var x = []; diff --git a/tests/baselines/reference/restUnion3.types b/tests/baselines/reference/restUnion3.types index 7c9daafae7904..24bc5e4a52ce4 100644 --- a/tests/baselines/reference/restUnion3.types +++ b/tests/baselines/reference/restUnion3.types @@ -11,7 +11,7 @@ var {...rest4 } = nullAndUndefinedUnion; >nullAndUndefinedUnion : null | undefined declare const unionWithIntersection: ({ n: number } & { s: string }) & undefined; ->unionWithIntersection : { n: number; } & { s: string; } & undefined +>unionWithIntersection : never >n : number >s : string @@ -22,5 +22,5 @@ var rest5: { n: number, s: string }; var {...rest5 } = unionWithIntersection; >rest5 : { n: number; s: string; } ->unionWithIntersection : { n: number; } & { s: string; } & undefined +>unionWithIntersection : never diff --git a/tests/baselines/reference/selfReferencingSpreadInLoop.js b/tests/baselines/reference/selfReferencingSpreadInLoop.js index 1b8d5ace4f3f5..023d33cca0c21 100644 --- a/tests/baselines/reference/selfReferencingSpreadInLoop.js +++ b/tests/baselines/reference/selfReferencingSpreadInLoop.js @@ -6,8 +6,15 @@ for (const subcomponent of [1, 2, 3]) { //// [selfReferencingSpreadInLoop.js] +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; var additional = []; for (var _i = 0, _a = [1, 2, 3]; _i < _a.length; _i++) { var subcomponent = _a[_i]; - additional = additional.concat([subcomponent]); + additional = __spreadArrays(additional, [subcomponent]); } diff --git a/tests/baselines/reference/spreadBooleanRespectsFreshness.js b/tests/baselines/reference/spreadBooleanRespectsFreshness.js index bb3ff104901d6..7b75533709143 100644 --- a/tests/baselines/reference/spreadBooleanRespectsFreshness.js +++ b/tests/baselines/reference/spreadBooleanRespectsFreshness.js @@ -8,4 +8,11 @@ declare let foo2: Foo; foo1 = [...Array.isArray(foo2) ? foo2 : [foo2]]; //// [spreadBooleanRespectsFreshness.js] -foo1 = (Array.isArray(foo2) ? foo2 : [foo2]).slice(); +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; +foo1 = __spreadArrays(Array.isArray(foo2) ? foo2 : [foo2]); diff --git a/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt b/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt deleted file mode 100644 index 380e98c3c3ddf..0000000000000 --- a/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt +++ /dev/null @@ -1,30 +0,0 @@ -tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts(22,10): error TS2678: Type 'boolean' is not comparable to type 'string & number'. - - -==== tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts (1 errors) ==== - var strAndNum: string & number; - var numAndBool: number & boolean; - var str: string; - var num: number; - var bool: boolean; - - switch (strAndNum) { - // Identical - case strAndNum: - break; - - // Constituents - case str: - case num: - break; - - // Overlap in constituents - case numAndBool: - break; - - // No relation - case bool: - ~~~~ -!!! error TS2678: Type 'boolean' is not comparable to type 'string & number'. - break; - } \ No newline at end of file diff --git a/tests/baselines/reference/switchCaseWithIntersectionTypes01.types b/tests/baselines/reference/switchCaseWithIntersectionTypes01.types index 9ba884985dc24..d6ba87f1e09fb 100644 --- a/tests/baselines/reference/switchCaseWithIntersectionTypes01.types +++ b/tests/baselines/reference/switchCaseWithIntersectionTypes01.types @@ -1,6 +1,6 @@ === tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts === var strAndNum: string & number; ->strAndNum : string & number +>strAndNum : never var numAndBool: number & boolean; >numAndBool : never @@ -15,11 +15,11 @@ var bool: boolean; >bool : boolean switch (strAndNum) { ->strAndNum : string & number +>strAndNum : never // Identical case strAndNum: ->strAndNum : string & number +>strAndNum : never break; diff --git a/tests/baselines/reference/tsxEmit1.js b/tests/baselines/reference/tsxEmit1.js index 5e9817b94d66d..6ca6d91bbe22f 100644 --- a/tests/baselines/reference/tsxEmit1.js +++ b/tests/baselines/reference/tsxEmit1.js @@ -41,6 +41,13 @@ var whitespace3 =
//// [file.jsx] +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; var p; var selfClosed1 =
; var selfClosed2 =
; @@ -60,10 +67,10 @@ var SomeClass = /** @class */ (function () { SomeClass.prototype.f = function () { var _this = this; var rewrites1 =
{function () { return _this; }}
; - var rewrites2 =
{[p].concat(p, [p])}
; + var rewrites2 =
{__spreadArrays([p], p, [p])}
; var rewrites3 =
{{ p: p }}
; var rewrites4 =
; - var rewrites5 =
; + var rewrites5 =
; var rewrites6 =
; }; return SomeClass; diff --git a/tests/baselines/reference/tsxReactEmit1.js b/tests/baselines/reference/tsxReactEmit1.js index 80b3c52ee20ed..28454c4dfb563 100644 --- a/tests/baselines/reference/tsxReactEmit1.js +++ b/tests/baselines/reference/tsxReactEmit1.js @@ -42,6 +42,13 @@ var whitespace3 =
//// [file.js] +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; var p; var selfClosed1 = React.createElement("div", null); var selfClosed2 = React.createElement("div", { x: "1" }); @@ -61,10 +68,10 @@ var SomeClass = /** @class */ (function () { SomeClass.prototype.f = function () { var _this = this; var rewrites1 = React.createElement("div", null, function () { return _this; }); - var rewrites2 = React.createElement("div", null, [p].concat(p, [p])); + var rewrites2 = React.createElement("div", null, __spreadArrays([p], p, [p])); var rewrites3 = React.createElement("div", null, { p: p }); var rewrites4 = React.createElement("div", { a: function () { return _this; } }); - var rewrites5 = React.createElement("div", { a: [p].concat(p, [p]) }); + var rewrites5 = React.createElement("div", { a: __spreadArrays([p], p, [p]) }); var rewrites6 = React.createElement("div", { a: { p: p } }); }; return SomeClass; diff --git a/tests/baselines/reference/tsxUnionElementType3.errors.txt b/tests/baselines/reference/tsxUnionElementType3.errors.txt index 8f8ce3c28bd73..73d8ccb0ce2b2 100644 --- a/tests/baselines/reference/tsxUnionElementType3.errors.txt +++ b/tests/baselines/reference/tsxUnionElementType3.errors.txt @@ -1,5 +1,4 @@ -tests/cases/conformance/jsx/file.tsx(32,17): error TS2322: Type 'string' is not assignable to type 'number & string'. - Type 'string' is not assignable to type 'number'. +tests/cases/conformance/jsx/file.tsx(32,17): error TS2322: Type 'string' is not assignable to type 'never'. ==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== @@ -36,8 +35,7 @@ tests/cases/conformance/jsx/file.tsx(32,17): error TS2322: Type 'string' is not // OK let a = ; ~ -!!! error TS2322: Type 'string' is not assignable to type 'number & string'. -!!! error TS2322: Type 'string' is not assignable to type 'number'. +!!! error TS2322: Type 'string' is not assignable to type 'never'. !!! related TS6500 tests/cases/conformance/jsx/file.tsx:3:36: The expected type comes from property 'x' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes & { x: number; } & { children?: ReactNode; } & { x: string; } & { children?: ReactNode; }' let a1 = ; let a2 = ; diff --git a/tests/baselines/reference/tsxUnionElementType4.errors.txt b/tests/baselines/reference/tsxUnionElementType4.errors.txt index 4b059d093f8ff..bca0229de54cf 100644 --- a/tests/baselines/reference/tsxUnionElementType4.errors.txt +++ b/tests/baselines/reference/tsxUnionElementType4.errors.txt @@ -1,5 +1,4 @@ -tests/cases/conformance/jsx/file.tsx(32,17): error TS2322: Type 'true' is not assignable to type 'number & string'. - Type 'true' is not assignable to type 'number'. +tests/cases/conformance/jsx/file.tsx(32,17): error TS2322: Type 'true' is not assignable to type 'never'. tests/cases/conformance/jsx/file.tsx(33,10): error TS2322: Type '{ x: number; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & { children?: ReactNode; }'. Property 'x' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & { children?: ReactNode; }'. tests/cases/conformance/jsx/file.tsx(34,10): error TS2322: Type '{ prop: true; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & { children?: ReactNode; }'. @@ -40,8 +39,7 @@ tests/cases/conformance/jsx/file.tsx(34,10): error TS2322: Type '{ prop: true; } // Error let a = ; ~ -!!! error TS2322: Type 'true' is not assignable to type 'number & string'. -!!! error TS2322: Type 'true' is not assignable to type 'number'. +!!! error TS2322: Type 'true' is not assignable to type 'never'. !!! related TS6500 tests/cases/conformance/jsx/file.tsx:3:36: The expected type comes from property 'x' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes & { x: number; } & { children?: ReactNode; } & { x: string; } & { children?: ReactNode; }' let b = ~~~~~~~~~~ diff --git a/tests/baselines/reference/typeGuardNarrowsPrimitiveIntersection.types b/tests/baselines/reference/typeGuardNarrowsPrimitiveIntersection.types index 262568a65cac9..a14629c3e2a9e 100644 --- a/tests/baselines/reference/typeGuardNarrowsPrimitiveIntersection.types +++ b/tests/baselines/reference/typeGuardNarrowsPrimitiveIntersection.types @@ -40,12 +40,12 @@ const enum Tag2 {} >Tag2 : Tag2 declare function isNonBlank2(value: string) : value is (string & Tag2); ->isNonBlank2 : (value: string) => value is string & Tag2 +>isNonBlank2 : (value: string) => value is never >value : string declare function doThis2(value: string & Tag2): void; ->doThis2 : (value: string & Tag2) => void ->value : string & Tag2 +>doThis2 : (value: never) => void +>value : never declare function doThat2(value: string) : void; >doThat2 : (value: string) => void @@ -53,13 +53,13 @@ declare function doThat2(value: string) : void; if (isNonBlank2(value)) { >isNonBlank2(value) : boolean ->isNonBlank2 : (value: string) => value is string & Tag2 +>isNonBlank2 : (value: string) => value is never >value : string doThis2(value); >doThis2(value) : void ->doThis2 : (value: string & Tag2) => void ->value : string & Tag2 +>doThis2 : (value: never) => void +>value : never } else { doThat2(value); diff --git a/tests/baselines/reference/unionAndIntersectionInference2.js b/tests/baselines/reference/unionAndIntersectionInference2.js index 18f08452a2ef5..8446213b3f1c5 100644 --- a/tests/baselines/reference/unionAndIntersectionInference2.js +++ b/tests/baselines/reference/unionAndIntersectionInference2.js @@ -20,8 +20,8 @@ var c2: string & { name: string } & number; var d2: string & { name: string } & number & { name: string }; f2(a2); // string f2(b2); // string[] -f2(c2); // string & number -f2(d2); // string & number +f2(c2); // never +f2(d2); // never //// [unionAndIntersectionInference2.js] @@ -41,5 +41,5 @@ var c2; var d2; f2(a2); // string f2(b2); // string[] -f2(c2); // string & number -f2(d2); // string & number +f2(c2); // never +f2(d2); // never diff --git a/tests/baselines/reference/unionAndIntersectionInference2.symbols b/tests/baselines/reference/unionAndIntersectionInference2.symbols index 24b1a36aa45e6..926286dde5220 100644 --- a/tests/baselines/reference/unionAndIntersectionInference2.symbols +++ b/tests/baselines/reference/unionAndIntersectionInference2.symbols @@ -75,11 +75,11 @@ f2(b2); // string[] >f2 : Symbol(f2, Decl(unionAndIntersectionInference2.ts, 11, 7)) >b2 : Symbol(b2, Decl(unionAndIntersectionInference2.ts, 16, 3)) -f2(c2); // string & number +f2(c2); // never >f2 : Symbol(f2, Decl(unionAndIntersectionInference2.ts, 11, 7)) >c2 : Symbol(c2, Decl(unionAndIntersectionInference2.ts, 17, 3)) -f2(d2); // string & number +f2(d2); // never >f2 : Symbol(f2, Decl(unionAndIntersectionInference2.ts, 11, 7)) >d2 : Symbol(d2, Decl(unionAndIntersectionInference2.ts, 18, 3)) diff --git a/tests/baselines/reference/unionAndIntersectionInference2.types b/tests/baselines/reference/unionAndIntersectionInference2.types index 0fac3f2fc1b76..a163b25ce2891 100644 --- a/tests/baselines/reference/unionAndIntersectionInference2.types +++ b/tests/baselines/reference/unionAndIntersectionInference2.types @@ -58,11 +58,11 @@ var b2: { name: string } & string[]; >name : string var c2: string & { name: string } & number; ->c2 : string & { name: string; } & number +>c2 : never >name : string var d2: string & { name: string } & number & { name: string }; ->d2 : string & { name: string; } & number & { name: string; } +>d2 : never >name : string >name : string @@ -76,13 +76,13 @@ f2(b2); // string[] >f2 : (x: T & { name: string; }) => T >b2 : { name: string; } & string[] -f2(c2); // string & number ->f2(c2) : string & number +f2(c2); // never +>f2(c2) : never >f2 : (x: T & { name: string; }) => T ->c2 : string & { name: string; } & number +>c2 : never -f2(d2); // string & number ->f2(d2) : string & number +f2(d2); // never +>f2(d2) : never >f2 : (x: T & { name: string; }) => T ->d2 : string & { name: string; } & number & { name: string; } +>d2 : never diff --git a/tests/baselines/reference/unionTypeCallSignatures.errors.txt b/tests/baselines/reference/unionTypeCallSignatures.errors.txt index f7a2c9d076686..2c80ac58cc8f4 100644 --- a/tests/baselines/reference/unionTypeCallSignatures.errors.txt +++ b/tests/baselines/reference/unionTypeCallSignatures.errors.txt @@ -2,10 +2,8 @@ tests/cases/conformance/types/union/unionTypeCallSignatures.ts(9,43): error TS23 tests/cases/conformance/types/union/unionTypeCallSignatures.ts(10,29): error TS2345: Argument of type 'true' is not assignable to parameter of type 'string'. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(15,29): error TS2345: Argument of type 'true' is not assignable to parameter of type 'string'. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(16,1): error TS2554: Expected 1 arguments, but got 0. -tests/cases/conformance/types/union/unionTypeCallSignatures.ts(19,32): error TS2345: Argument of type '10' is not assignable to parameter of type 'number & string'. - Type '10' is not assignable to type 'string'. -tests/cases/conformance/types/union/unionTypeCallSignatures.ts(20,32): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number & string'. - Type '"hello"' is not assignable to type 'number'. +tests/cases/conformance/types/union/unionTypeCallSignatures.ts(19,32): error TS2345: Argument of type '10' is not assignable to parameter of type 'never'. +tests/cases/conformance/types/union/unionTypeCallSignatures.ts(20,32): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'never'. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(21,1): error TS2554: Expected 1 arguments, but got 0. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(24,1): error TS2554: Expected 1 arguments, but got 0. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(26,36): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. @@ -59,12 +57,10 @@ tests/cases/conformance/types/union/unionTypeCallSignatures.ts(73,12): error TS2 var unionOfDifferentParameterTypes: { (a: number): number; } | { (a: string): Date; }; unionOfDifferentParameterTypes(10);// error - no call signatures ~~ -!!! error TS2345: Argument of type '10' is not assignable to parameter of type 'number & string'. -!!! error TS2345: Type '10' is not assignable to type 'string'. +!!! error TS2345: Argument of type '10' is not assignable to parameter of type 'never'. unionOfDifferentParameterTypes("hello");// error - no call signatures ~~~~~~~ -!!! error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number & string'. -!!! error TS2345: Type '"hello"' is not assignable to type 'number'. +!!! error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'never'. unionOfDifferentParameterTypes();// error - no call signatures ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2554: Expected 1 arguments, but got 0. diff --git a/tests/baselines/reference/unionTypeConstructSignatures.errors.txt b/tests/baselines/reference/unionTypeConstructSignatures.errors.txt index d420d95f3b157..d46f616e53ef0 100644 --- a/tests/baselines/reference/unionTypeConstructSignatures.errors.txt +++ b/tests/baselines/reference/unionTypeConstructSignatures.errors.txt @@ -2,10 +2,8 @@ tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(9,47): error tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(10,33): error TS2345: Argument of type 'true' is not assignable to parameter of type 'string'. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(15,33): error TS2345: Argument of type 'true' is not assignable to parameter of type 'string'. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(16,1): error TS2554: Expected 1 arguments, but got 0. -tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(19,36): error TS2345: Argument of type '10' is not assignable to parameter of type 'number & string'. - Type '10' is not assignable to type 'string'. -tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(20,36): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number & string'. - Type '"hello"' is not assignable to type 'number'. +tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(19,36): error TS2345: Argument of type '10' is not assignable to parameter of type 'never'. +tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(20,36): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'never'. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(21,1): error TS2554: Expected 1 arguments, but got 0. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(24,1): error TS2554: Expected 1 arguments, but got 0. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(26,40): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. @@ -58,12 +56,10 @@ tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(70,12): erro var unionOfDifferentParameterTypes: { new (a: number): number; } | { new (a: string): Date; }; new unionOfDifferentParameterTypes(10);// error - no call signatures ~~ -!!! error TS2345: Argument of type '10' is not assignable to parameter of type 'number & string'. -!!! error TS2345: Type '10' is not assignable to type 'string'. +!!! error TS2345: Argument of type '10' is not assignable to parameter of type 'never'. new unionOfDifferentParameterTypes("hello");// error - no call signatures ~~~~~~~ -!!! error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number & string'. -!!! error TS2345: Type '"hello"' is not assignable to type 'number'. +!!! error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'never'. new unionOfDifferentParameterTypes();// error - no call signatures ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2554: Expected 1 arguments, but got 0. diff --git a/tests/baselines/reference/unionTypeMembers.errors.txt b/tests/baselines/reference/unionTypeMembers.errors.txt index 2a2f93d1a071c..8c18e200d916d 100644 --- a/tests/baselines/reference/unionTypeMembers.errors.txt +++ b/tests/baselines/reference/unionTypeMembers.errors.txt @@ -1,6 +1,5 @@ -tests/cases/conformance/types/union/unionTypeMembers.ts(44,38): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string & number'. - Type 'string' is not assignable to type 'string & number'. - Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/union/unionTypeMembers.ts(44,38): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'never'. + Type 'string' is not assignable to type 'never'. tests/cases/conformance/types/union/unionTypeMembers.ts(51,3): error TS2339: Property 'propertyOnlyInI1' does not exist on type 'I1 | I2'. Property 'propertyOnlyInI1' does not exist on type 'I2'. tests/cases/conformance/types/union/unionTypeMembers.ts(52,3): error TS2339: Property 'propertyOnlyInI2' does not exist on type 'I1 | I2'. @@ -57,9 +56,8 @@ tests/cases/conformance/types/union/unionTypeMembers.ts(54,3): error TS2339: Pro x.commonMethodDifferentParameterType; // No error - property exists x.commonMethodDifferentParameterType(strOrNum); // error - no call signatures because the type of this property is ((a: string) => string) | (a: number) => number ~~~~~~~~ -!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string & number'. -!!! error TS2345: Type 'string' is not assignable to type 'string & number'. -!!! error TS2345: Type 'string' is not assignable to type 'number'. +!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'never'. +!!! error TS2345: Type 'string' is not assignable to type 'never'. // and the call signatures arent identical num = x.commonMethodWithTypeParameter(num); num = x.commonMethodWithOwnTypeParameter(num); diff --git a/tests/baselines/reference/unknownType1.errors.txt b/tests/baselines/reference/unknownType1.errors.txt index 93e2a8660f65e..c3d5f891fb0d8 100644 --- a/tests/baselines/reference/unknownType1.errors.txt +++ b/tests/baselines/reference/unknownType1.errors.txt @@ -35,7 +35,7 @@ tests/cases/conformance/types/unknown/unknownType1.ts(180,5): error TS2322: Type type T00 = unknown & null; // null type T01 = unknown & undefined; // undefined - type T02 = unknown & null & undefined; // null & undefined (which becomes never in union) + type T02 = unknown & null & undefined; // never type T03 = unknown & string; // string type T04 = unknown & string[]; // string[] type T05 = unknown & unknown; // unknown diff --git a/tests/baselines/reference/unknownType1.js b/tests/baselines/reference/unknownType1.js index a5183fd50294c..688fbf8f93c01 100644 --- a/tests/baselines/reference/unknownType1.js +++ b/tests/baselines/reference/unknownType1.js @@ -3,7 +3,7 @@ type T00 = unknown & null; // null type T01 = unknown & undefined; // undefined -type T02 = unknown & null & undefined; // null & undefined (which becomes never in union) +type T02 = unknown & null & undefined; // never type T03 = unknown & string; // string type T04 = unknown & string[]; // string[] type T05 = unknown & unknown; // unknown diff --git a/tests/baselines/reference/unknownType1.symbols b/tests/baselines/reference/unknownType1.symbols index d4bdffc0163c8..95a3587baabd8 100644 --- a/tests/baselines/reference/unknownType1.symbols +++ b/tests/baselines/reference/unknownType1.symbols @@ -7,7 +7,7 @@ type T00 = unknown & null; // null type T01 = unknown & undefined; // undefined >T01 : Symbol(T01, Decl(unknownType1.ts, 2, 26)) -type T02 = unknown & null & undefined; // null & undefined (which becomes never in union) +type T02 = unknown & null & undefined; // never >T02 : Symbol(T02, Decl(unknownType1.ts, 3, 31)) type T03 = unknown & string; // string diff --git a/tests/baselines/reference/unknownType1.types b/tests/baselines/reference/unknownType1.types index a464864d0d19d..7d28468169846 100644 --- a/tests/baselines/reference/unknownType1.types +++ b/tests/baselines/reference/unknownType1.types @@ -8,8 +8,8 @@ type T00 = unknown & null; // null type T01 = unknown & undefined; // undefined >T01 : undefined -type T02 = unknown & null & undefined; // null & undefined (which becomes never in union) ->T02 : T02 +type T02 = unknown & null & undefined; // never +>T02 : never >null : null type T03 = unknown & string; // string diff --git a/tests/baselines/reference/user/chrome-devtools-frontend.log b/tests/baselines/reference/user/chrome-devtools-frontend.log index 7c51aef515902..6b6b46ab180df 100644 --- a/tests/baselines/reference/user/chrome-devtools-frontend.log +++ b/tests/baselines/reference/user/chrome-devtools-frontend.log @@ -3012,15 +3012,7 @@ node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighth node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(65285,7): error TS2339: Property 'description' does not exist on type 'Error'. node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(65310,1): error TS2323: Cannot redeclare exported variable '__esModule'. node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(65379,1): error TS2323: Cannot redeclare exported variable '__esModule'. -node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(65443,1): error TS2322: Type '{ line: number; column: number; }' is not assignable to type '{}'. - Property 'line' does not exist on type '{}'. -node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(65464,1): error TS2322: Type '{ line: number; column: number; }' is not assignable to type '{}'. - Property 'line' does not exist on type '{}'. node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(65468,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'entry' must be of type '{ multiLine: boolean; slice: any[]; range: number[]; loc: { start: { line: number; column: number; }; end: {}; }; }', but here has type '{ multiLine: boolean; slice: any[]; range: any[]; loc: { start: { line: number; column: number; }; end: {}; }; }'. -node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(65507,1): error TS2322: Type '{ line: number; column: number; }' is not assignable to type '{}'. - Property 'line' does not exist on type '{}'. -node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(65529,1): error TS2322: Type '{ line: number; column: number; }' is not assignable to type '{}'. - Property 'line' does not exist on type '{}'. node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(65533,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'entry' must be of type '{ multiLine: boolean; slice: number[]; range: any[]; loc: { start: { line: number; column: number; }; end: {}; }; }', but here has type '{ multiLine: boolean; slice: any[]; range: any[]; loc: { start: { line: number; column: number; }; end: {}; }; }'. node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(65576,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'comment' must be of type '{ multiLine: boolean; slice: any[]; range: number[]; loc: { start: { line: number; column: number; }; end: {}; }; }[]', but here has type '{ multiLine: boolean; slice: number[]; range: any[]; loc: { start: { line: number; column: number; }; end: {}; }; }[]'. node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(66529,1): error TS2323: Cannot redeclare exported variable '__esModule'. diff --git a/tests/baselines/reference/user/prettier.log b/tests/baselines/reference/user/prettier.log index 2082b66ee5956..6ee6e91cb6bc2 100644 --- a/tests/baselines/reference/user/prettier.log +++ b/tests/baselines/reference/user/prettier.log @@ -160,13 +160,6 @@ src/language-js/printer-estree.js(1892,20): error TS2345: Argument of type '{ ty src/language-js/printer-estree.js(1894,18): error TS2345: Argument of type '"while ("' is not assignable to parameter of type '{ type: string; id: any; contents: any; break: boolean; expandedStates: any; }'. src/language-js/printer-estree.js(1903,9): error TS2345: Argument of type '")"' is not assignable to parameter of type '{ type: string; id: any; contents: any; break: boolean; expandedStates: any; }'. src/language-js/printer-estree.js(2426,28): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'. -src/language-js/printer-estree.js(2446,13): error TS2345: Argument of type '{ hasLineBreak: boolean; cells: never[]; }[]' is not assignable to parameter of type '{ cells: any; } | ConcatArray<{ cells: any; }>'. - Type '{ hasLineBreak: boolean; cells: never[]; }[]' is not assignable to type 'ConcatArray<{ cells: any; }>'. - Types of property 'slice' are incompatible. - Type '(start?: number | undefined, end?: number | undefined) => { hasLineBreak: boolean; cells: never[]; }[]' is not assignable to type '(start?: number | undefined, end?: number | undefined) => { cells: any; }[]'. - Type '{ hasLineBreak: boolean; cells: never[]; }[]' is not assignable to type '{ cells: any; }[]'. - Type '{ hasLineBreak: boolean; cells: never[]; }' is not assignable to type '{ cells: any; }'. - Property 'hasLineBreak' does not exist on type '{ cells: any; }'. src/language-js/printer-estree.js(3513,11): error TS2345: Argument of type 'never[] | { type: string; parts: any; }' is not assignable to parameter of type 'ConcatArray'. Type '{ type: string; parts: any; }' is not assignable to type 'ConcatArray'. src/language-js/printer-estree.js(4031,23): error TS2532: Object is possibly 'undefined'. diff --git a/tests/cases/conformance/types/conditional/inferTypes1.ts b/tests/cases/conformance/types/conditional/inferTypes1.ts index 83d6bd0c0b317..3be629b86ba88 100644 --- a/tests/cases/conformance/types/conditional/inferTypes1.ts +++ b/tests/cases/conformance/types/conditional/inferTypes1.ts @@ -71,7 +71,7 @@ type X3 = T extends { a: (x: infer U) => void, b: (x: infer U) => void } ? U type T50 = X3<{}>; // never type T51 = X3<{ a: (x: string) => void }>; // never type T52 = X3<{ a: (x: string) => void, b: (x: string) => void }>; // string -type T53 = X3<{ a: (x: number) => void, b: (x: string) => void }>; // string & number +type T53 = X3<{ a: (x: number) => void, b: (x: string) => void }>; // never type T54 = X3<{ a: (x: number) => void, b: () => void }>; // number type T60 = infer U; // Error diff --git a/tests/cases/conformance/types/intersection/intersectionReduction.ts b/tests/cases/conformance/types/intersection/intersectionReduction.ts index b3b8950c33064..128f6fd067ab7 100644 --- a/tests/cases/conformance/types/intersection/intersectionReduction.ts +++ b/tests/cases/conformance/types/intersection/intersectionReduction.ts @@ -1,15 +1,58 @@ -// @strict +// @strict: false declare const sym1: unique symbol; declare const sym2: unique symbol; type T1 = string & 'a'; // 'a' -type T2 = 'a' & string & 'b'; // 'a' & 'b' +type T2 = 'a' & string & 'b'; // never type T3 = number & 10; // 10 -type T4 = 10 & number & 20; // 10 & 20 +type T4 = 10 & number & 20; // never type T5 = symbol & typeof sym1; // typeof sym1 -type T6 = typeof sym1 & symbol & typeof sym2; // typeof sym1 & typeof sym2 -type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // 'a' & 10 & typeof sym1 +type T6 = typeof sym1 & symbol & typeof sym2; // never +type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never type T10 = string & ('a' | 'b'); // 'a' | 'b' type T11 = (string | number) & ('a' | 10); // 'a' | 10 + +type N1 = 'a' & 'b'; +type N2 = { a: string } & null; +type N3 = { a: string } & undefined; +type N4 = string & number; +type N5 = number & object; +type N6 = symbol & string; +type N7 = void & string; + +type X = { x: string }; + +type X1 = X | 'a' & 'b'; +type X2 = X | { a: string } & null; +type X3 = X | { a: string } & undefined; +type X4 = X | string & number; +type X5 = X | number & object; +type X6 = X | symbol & string; +type X7 = X | void & string; + +// Repro from #31663 + +const x1 = { a: 'foo', b: 42 }; +const x2 = { a: 'foo', b: true }; + +declare let k: 'a' | 'b'; + +x1[k] = 'bar' as any; // Error +x2[k] = 'bar' as any; // Error + +const enum Tag1 {} +const enum Tag2 {} + +declare let s1: string & Tag1; +declare let s2: string & Tag2; + +declare let t1: string & Tag1 | undefined; +declare let t2: string & Tag2 | undefined; + +s1 = s2; +s2 = s1; + +t1 = t2; +t2 = t1; diff --git a/tests/cases/conformance/types/intersection/intersectionReductionStrict.ts b/tests/cases/conformance/types/intersection/intersectionReductionStrict.ts new file mode 100644 index 0000000000000..2136f99db9ff9 --- /dev/null +++ b/tests/cases/conformance/types/intersection/intersectionReductionStrict.ts @@ -0,0 +1,58 @@ +// @strict: true + +declare const sym1: unique symbol; +declare const sym2: unique symbol; + +type T1 = string & 'a'; // 'a' +type T2 = 'a' & string & 'b'; // never +type T3 = number & 10; // 10 +type T4 = 10 & number & 20; // never +type T5 = symbol & typeof sym1; // typeof sym1 +type T6 = typeof sym1 & symbol & typeof sym2; // never +type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never + +type T10 = string & ('a' | 'b'); // 'a' | 'b' +type T11 = (string | number) & ('a' | 10); // 'a' | 10 + +type N1 = 'a' & 'b'; +type N2 = { a: string } & null; +type N3 = { a: string } & undefined; +type N4 = string & number; +type N5 = number & object; +type N6 = symbol & string; +type N7 = void & string; + +type X = { x: string }; + +type X1 = X | 'a' & 'b'; +type X2 = X | { a: string } & null; +type X3 = X | { a: string } & undefined; +type X4 = X | string & number; +type X5 = X | number & object; +type X6 = X | symbol & string; +type X7 = X | void & string; + +// Repro from #31663 + +const x1 = { a: 'foo', b: 42 }; +const x2 = { a: 'foo', b: true }; + +declare let k: 'a' | 'b'; + +x1[k] = 'bar' as any; // Error +x2[k] = 'bar' as any; // Error + +const enum Tag1 {} +const enum Tag2 {} + +declare let s1: string & Tag1; +declare let s2: string & Tag2; + +declare let t1: string & Tag1 | undefined; +declare let t2: string & Tag2 | undefined; + +s1 = s2; +s2 = s1; + +t1 = t2; +t2 = t1; diff --git a/tests/cases/conformance/types/intersection/intersectionTypeInference2.ts b/tests/cases/conformance/types/intersection/intersectionTypeInference2.ts index d32441cfee83a..d4ed0d9f970f5 100644 --- a/tests/cases/conformance/types/intersection/intersectionTypeInference2.ts +++ b/tests/cases/conformance/types/intersection/intersectionTypeInference2.ts @@ -3,8 +3,8 @@ declare function f(x: { prop: T }): T; declare const a: { prop: string } & { prop: number }; declare const b: { prop: string & number }; -f(a); // string & number -f(b); // string & number +f(a); // never +f(b); // never // Repro from #18354 diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts index d5fe7c24b5c66..a8666841c85b1 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts @@ -27,7 +27,7 @@ type T17 = Shape[void]; // Error type T18 = Shape[undefined]; // Error type T19 = Shape[{ x: string }]; // Error type T20 = Shape[string | number]; // Error -type T21 = Shape[string & number]; // Error +type T21 = Shape[string & number]; type T22 = Shape[string | boolean]; // Error type T30 = string[]["length"]; diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/unionAndIntersectionInference2.ts b/tests/cases/conformance/types/typeRelationships/typeInference/unionAndIntersectionInference2.ts index 1b6a928ce028c..274b46e3ad657 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/unionAndIntersectionInference2.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/unionAndIntersectionInference2.ts @@ -19,5 +19,5 @@ var c2: string & { name: string } & number; var d2: string & { name: string } & number & { name: string }; f2(a2); // string f2(b2); // string[] -f2(c2); // string & number -f2(d2); // string & number +f2(c2); // never +f2(d2); // never diff --git a/tests/cases/conformance/types/unknown/unknownType1.ts b/tests/cases/conformance/types/unknown/unknownType1.ts index 633b1407f9686..f96d1bb32c69b 100644 --- a/tests/cases/conformance/types/unknown/unknownType1.ts +++ b/tests/cases/conformance/types/unknown/unknownType1.ts @@ -4,7 +4,7 @@ type T00 = unknown & null; // null type T01 = unknown & undefined; // undefined -type T02 = unknown & null & undefined; // null & undefined (which becomes never in union) +type T02 = unknown & null & undefined; // never type T03 = unknown & string; // string type T04 = unknown & string[]; // string[] type T05 = unknown & unknown; // unknown diff --git a/tests/cases/fourslash/tsxQuickInfo6.ts b/tests/cases/fourslash/tsxQuickInfo6.ts index b00216b864e56..e9736b96bc73f 100644 --- a/tests/cases/fourslash/tsxQuickInfo6.ts +++ b/tests/cases/fourslash/tsxQuickInfo6.ts @@ -15,5 +15,5 @@ verify.quickInfos({ 1: "function ComponentSpecific(l: {\n prop: number;\n}): any", - 2: "function ComponentSpecific(l: {\n prop: number & string;\n}): any" + 2: "function ComponentSpecific(l: {\n prop: never;\n}): any" }); diff --git a/tests/cases/fourslash/tsxQuickInfo7.ts b/tests/cases/fourslash/tsxQuickInfo7.ts index 8b3493dd8d4e5..c434276621adb 100644 --- a/tests/cases/fourslash/tsxQuickInfo7.ts +++ b/tests/cases/fourslash/tsxQuickInfo7.ts @@ -24,6 +24,6 @@ verify.quickInfos({ 3: "function OverloadComponent(attr: {\n b: string;\n a: boolean;\n}): any (+2 overloads)", 4: "function OverloadComponent(): any (+2 overloads)", // Subtype pass chooses this overload, since `a` is missing from the top overload, and `ignore-prop` is missing from the second (while T & {ignore-prop: true} is a proper subtype of `{}`) 5: "function OverloadComponent(): any (+2 overloads)", - 6: "function OverloadComponent(attr: {\n b: string & number;\n a: boolean;\n}): any (+2 overloads)", - 7: "function OverloadComponent(attr: {\n b: number & string;\n a: boolean;\n}): any (+2 overloads)", + 6: "function OverloadComponent(attr: {\n b: never;\n a: boolean;\n}): any (+2 overloads)", + 7: "function OverloadComponent(attr: {\n b: never;\n a: boolean;\n}): any (+2 overloads)", });