From 43981eaa48b70017666875d7c6f325fd9bf5aa6b Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 25 Jul 2017 09:38:55 -0700 Subject: [PATCH 1/8] Use type param constraints for computed prop types --- src/compiler/checker.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c2f40c169dc3f..6da61b974f18e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13330,10 +13330,13 @@ namespace ts { const links = getNodeLinks(node.expression); if (!links.resolvedType) { links.resolvedType = checkExpression(node.expression); + const t = links.resolvedType.flags & TypeFlags.TypeVariable ? + getBaseConstraintOfType(links.resolvedType) || emptyObjectType : + links.resolvedType; // This will allow types number, string, symbol or any. It will also allow enums, the unknown // type, and any union of these types (like string | number). - if (!isTypeAnyOrAllConstituentTypesHaveKind(links.resolvedType, TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.ESSymbol)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(t, TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.ESSymbol)) { error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); } else { From 1fb6d349f1148ab87fbe43cabf099790a4657530 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 25 Jul 2017 09:39:54 -0700 Subject: [PATCH 2/8] Test:use type param constraints for computed prop types --- .../computedPropertyNames51_ES5.errors.txt | 15 +++++++++++++ .../reference/computedPropertyNames51_ES5.js | 21 +++++++++++++++++++ .../computedPropertyNames51_ES6.errors.txt | 15 +++++++++++++ .../reference/computedPropertyNames51_ES6.js | 20 ++++++++++++++++++ .../computedPropertyNames8_ES5.errors.txt | 5 +---- .../computedPropertyNames8_ES6.errors.txt | 5 +---- .../computedPropertyNames51_ES5.ts | 8 +++++++ .../computedPropertyNames51_ES6.ts | 9 ++++++++ 8 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 tests/baselines/reference/computedPropertyNames51_ES5.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames51_ES5.js create mode 100644 tests/baselines/reference/computedPropertyNames51_ES6.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames51_ES6.js create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames51_ES5.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames51_ES6.ts diff --git a/tests/baselines/reference/computedPropertyNames51_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames51_ES5.errors.txt new file mode 100644 index 0000000000000..3ee876feaed1f --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames51_ES5.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames51_ES5.ts(5,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames51_ES5.ts (1 errors) ==== + function f() { + var t: T; + var k: K; + var v = { + [t]: 0, + ~~~ +!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. + [k]: 1 + }; + } + \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames51_ES5.js b/tests/baselines/reference/computedPropertyNames51_ES5.js new file mode 100644 index 0000000000000..9f138b37f3dab --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames51_ES5.js @@ -0,0 +1,21 @@ +//// [computedPropertyNames51_ES5.ts] +function f() { + var t: T; + var k: K; + var v = { + [t]: 0, + [k]: 1 + }; +} + + +//// [computedPropertyNames51_ES5.js] +function f() { + var t; + var k; + var v = (_a = {}, + _a[t] = 0, + _a[k] = 1, + _a); + var _a; +} diff --git a/tests/baselines/reference/computedPropertyNames51_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames51_ES6.errors.txt new file mode 100644 index 0000000000000..b85ae8f48d04b --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames51_ES6.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames51_ES6.ts(5,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames51_ES6.ts (1 errors) ==== + function f() { + var t: T; + var k: K; + var v = { + [t]: 0, + ~~~ +!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. + [k]: 1 + }; + } + \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames51_ES6.js b/tests/baselines/reference/computedPropertyNames51_ES6.js new file mode 100644 index 0000000000000..361af9cc15a6b --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames51_ES6.js @@ -0,0 +1,20 @@ +//// [computedPropertyNames51_ES6.ts] +function f() { + var t: T; + var k: K; + var v = { + [t]: 0, + [k]: 1 + }; +} + + +//// [computedPropertyNames51_ES6.js] +function f() { + var t; + var k; + var v = { + [t]: 0, + [k]: 1 + }; +} diff --git a/tests/baselines/reference/computedPropertyNames8_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames8_ES5.errors.txt index 9fbd14a92fb07..56dbe16a52317 100644 --- a/tests/baselines/reference/computedPropertyNames8_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames8_ES5.errors.txt @@ -1,8 +1,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames8_ES5.ts(5,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames8_ES5.ts(6,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -==== tests/cases/conformance/es6/computedProperties/computedPropertyNames8_ES5.ts (2 errors) ==== +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames8_ES5.ts (1 errors) ==== function f() { var t: T; var u: U; @@ -11,7 +10,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames8_ES5.ts(6,9 ~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. [u]: 1 - ~~~ -!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. }; } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames8_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames8_ES6.errors.txt index 22674a3992cbc..9996f35f063c7 100644 --- a/tests/baselines/reference/computedPropertyNames8_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames8_ES6.errors.txt @@ -1,8 +1,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames8_ES6.ts(5,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames8_ES6.ts(6,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -==== tests/cases/conformance/es6/computedProperties/computedPropertyNames8_ES6.ts (2 errors) ==== +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames8_ES6.ts (1 errors) ==== function f() { var t: T; var u: U; @@ -11,7 +10,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames8_ES6.ts(6,9 ~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. [u]: 1 - ~~~ -!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. }; } \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames51_ES5.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames51_ES5.ts new file mode 100644 index 0000000000000..1d467245fb2ce --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames51_ES5.ts @@ -0,0 +1,8 @@ +function f() { + var t: T; + var k: K; + var v = { + [t]: 0, + [k]: 1 + }; +} diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames51_ES6.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames51_ES6.ts new file mode 100644 index 0000000000000..ca209996c4c3c --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames51_ES6.ts @@ -0,0 +1,9 @@ +// @target: es6 +function f() { + var t: T; + var k: K; + var v = { + [t]: 0, + [k]: 1 + }; +} From 838fbdd9ca5902308af91ce6dee45e2a66f8c719 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 26 Jul 2017 16:28:24 -0700 Subject: [PATCH 3/8] Make isTypeOfKind delegate to isTypeAssignableTo This improves a number of error messages to do with adding 'null' or 'undefined' with other types. It also allows you to add two type parameters that both extend `number`. --- src/compiler/checker.ts | 89 ++++++++++--------- ...WithNullValueAndInvalidOperator.errors.txt | 66 +++++++------- ...orWithNullValueAndValidOperator.errors.txt | 60 ++++++------- ...thOnlyNullValueOrUndefinedValue.errors.txt | 38 +++----- ...ditionOperatorWithTypeParameter.errors.txt | 12 +-- ...ndefinedValueAndInvalidOperands.errors.txt | 66 +++++++------- ...hUndefinedValueAndValidOperator.errors.txt | 60 ++++++------- ...wiseNotOperatorWithAnyOtherType.errors.txt | 29 +++--- ...itionAssignmentLHSCanBeAssigned.errors.txt | 24 ++--- ...onAssignmentWithInvalidOperands.errors.txt | 36 ++++---- ...thAnyOtherTypeInvalidOperations.errors.txt | 56 ++++-------- .../deleteOperatorWithAnyOtherType.errors.txt | 29 +++--- ...thAnyOtherTypeInvalidOperations.errors.txt | 56 ++++-------- ...icalNotOperatorWithAnyOtherType.errors.txt | 29 +++--- tests/baselines/reference/null.errors.txt | 6 +- .../operatorAddNullUndefined.errors.txt | 86 ++++++++---------- .../plusOperatorWithAnyOtherType.errors.txt | 29 +++--- .../reference/typeParamExtendsNumber.js | 19 ++++ .../reference/typeParamExtendsNumber.symbols | 20 +++++ .../reference/typeParamExtendsNumber.types | 23 +++++ .../typeofOperatorWithAnyOtherType.errors.txt | 29 +++--- .../voidOperatorWithAnyOtherType.errors.txt | 29 +++--- .../cases/compiler/typeParamExtendsNumber.ts | 7 ++ 23 files changed, 429 insertions(+), 469 deletions(-) create mode 100644 tests/baselines/reference/typeParamExtendsNumber.js create mode 100644 tests/baselines/reference/typeParamExtendsNumber.symbols create mode 100644 tests/baselines/reference/typeParamExtendsNumber.types create mode 100644 tests/cases/compiler/typeParamExtendsNumber.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6da61b974f18e..d1c18ef61d807 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7526,11 +7526,11 @@ namespace ts { return getTypeOfSymbol(prop); } } - if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { + if (!(indexType.flags & TypeFlags.Nullable) && isTypeOfKind(indexType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { if (isTypeAny(objectType)) { return anyType; } - const indexInfo = isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.NumberLike) && getIndexInfoOfType(objectType, IndexKind.Number) || + const indexInfo = isTypeOfKind(indexType, TypeFlags.NumberLike) && getIndexInfoOfType(objectType, IndexKind.Number) || getIndexInfoOfType(objectType, IndexKind.String) || undefined; if (indexInfo) { @@ -11286,7 +11286,7 @@ namespace ts { (parent.parent).operatorToken.kind === SyntaxKind.EqualsToken && (parent.parent).left === parent && !isAssignmentTarget(parent.parent) && - isTypeAnyOrAllConstituentTypesHaveKind(getTypeOfExpression((parent).argumentExpression), TypeFlags.NumberLike | TypeFlags.Undefined); + isTypeOfKind(getTypeOfExpression((parent).argumentExpression), TypeFlags.NumberLike); return isLengthPushOrUnshift || isElementAssignment; } @@ -11458,7 +11458,7 @@ namespace ts { } else { const indexType = getTypeOfExpression(((node).left).argumentExpression); - if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.NumberLike | TypeFlags.Undefined)) { + if (isTypeOfKind(indexType, TypeFlags.NumberLike)) { evolvedType = addEvolvingArrayElementType(evolvedType, (node).right); } } @@ -13290,11 +13290,7 @@ namespace ts { function isNumericComputedName(name: ComputedPropertyName): boolean { // It seems odd to consider an expression of type Any to result in a numeric name, // but this behavior is consistent with checkIndexedAccess - return isTypeAnyOrAllConstituentTypesHaveKind(checkComputedPropertyName(name), TypeFlags.NumberLike); - } - - function isTypeAnyOrAllConstituentTypesHaveKind(type: Type, kind: TypeFlags): boolean { - return isTypeAny(type) || isTypeOfKind(type, kind); + return isTypeOfKind(checkComputedPropertyName(name), TypeFlags.NumberLike); } function isInfinityOrNaNString(name: string | __String): boolean { @@ -13330,13 +13326,9 @@ namespace ts { const links = getNodeLinks(node.expression); if (!links.resolvedType) { links.resolvedType = checkExpression(node.expression); - const t = links.resolvedType.flags & TypeFlags.TypeVariable ? - getBaseConstraintOfType(links.resolvedType) || emptyObjectType : - links.resolvedType; - // This will allow types number, string, symbol or any. It will also allow enums, the unknown // type, and any union of these types (like string | number). - if (!isTypeAnyOrAllConstituentTypesHaveKind(t, TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.ESSymbol)) { + if (links.resolvedType.flags & TypeFlags.Nullable || !isTypeOfKind(links.resolvedType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); } else { @@ -16821,7 +16813,7 @@ namespace ts { } function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage): boolean { - if (!isTypeAnyOrAllConstituentTypesHaveKind(type, TypeFlags.NumberLike)) { + if (!isTypeOfKind(type, TypeFlags.NumberLike)) { error(operand, diagnostic); return false; } @@ -16994,31 +16986,43 @@ namespace ts { return false; } - // Return true if type is of the given kind. A union type is of a given kind if all constituent types - // are of the given kind. An intersection type is of a given kind if at least one constituent type is - // of the given kind. - function isTypeOfKind(type: Type, kind: TypeFlags): boolean { - if (type.flags & kind) { + function isTypeOfKind(source: Type, kind: TypeFlags, excludeAny?: boolean) { + if (source.flags & kind) { return true; } - if (type.flags & TypeFlags.Union) { - const types = (type).types; - for (const t of types) { - if (!isTypeOfKind(t, kind)) { - return false; - } - } - return true; + if (excludeAny && source.flags & (TypeFlags.Any | TypeFlags.Void | TypeFlags.Undefined | TypeFlags.Null)) { + // TODO: The callers who want this should really handle these cases FIRST + return false; } - if (type.flags & TypeFlags.Intersection) { - const types = (type).types; - for (const t of types) { - if (isTypeOfKind(t, kind)) { - return true; - } - } + const targets = []; + if (kind & TypeFlags.NumberLike) { + targets.push(numberType); } - return false; + if (kind & TypeFlags.StringLike) { + targets.push(stringType); + } + if (kind & TypeFlags.BooleanLike) { + targets.push(booleanType); + } + if (kind & TypeFlags.Void) { + targets.push(voidType); + } + if (kind & TypeFlags.Never) { + targets.push(neverType); + } + if (kind & TypeFlags.Null) { + targets.push(nullType); + } + if (kind & TypeFlags.Undefined) { + targets.push(undefinedType); + } + if (kind & TypeFlags.ESSymbol) { + targets.push(esSymbolType); + } + if (kind & TypeFlags.NonPrimitive) { + targets.push(nonPrimitiveType); + } + return isTypeAssignableTo(source, getUnionType(targets)); } function isConstEnumObjectType(type: Type): boolean { @@ -17038,7 +17042,7 @@ namespace ts { // and the right operand to be of type Any, a subtype of the 'Function' interface type, or have a call or construct signature. // The result is always of the Boolean primitive type. // NOTE: do not raise error if leftType is unknown as related error was already reported - if (isTypeOfKind(leftType, TypeFlags.Primitive)) { + if (isTypeOfKind(leftType, TypeFlags.Primitive, /*excludeAny*/ true)) { error(left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported @@ -17064,7 +17068,7 @@ namespace ts { if (!(isTypeComparableTo(leftType, stringType) || isTypeOfKind(leftType, TypeFlags.NumberLike | TypeFlags.ESSymbol))) { error(left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } - if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.Object | TypeFlags.TypeVariable | TypeFlags.NonPrimitive)) { + if (!isTypeOfKind(rightType, TypeFlags.NonPrimitive | TypeFlags.TypeVariable)) { error(right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -17373,25 +17377,26 @@ namespace ts { return silentNeverType; } - if (!isTypeOfKind(leftType, TypeFlags.Any | TypeFlags.StringLike) && !isTypeOfKind(rightType, TypeFlags.Any | TypeFlags.StringLike)) { + if (!isTypeOfKind(leftType, TypeFlags.StringLike) && !isTypeOfKind(rightType, TypeFlags.StringLike)) { leftType = checkNonNullType(leftType, left); rightType = checkNonNullType(rightType, right); } let resultType: Type; - if (isTypeOfKind(leftType, TypeFlags.NumberLike) && isTypeOfKind(rightType, TypeFlags.NumberLike)) { + if (isTypeOfKind(leftType, TypeFlags.NumberLike, /*excludeAny*/ true) && isTypeOfKind(rightType, TypeFlags.NumberLike, /*excludeAny*/ true)) { // Operands of an enum type are treated as having the primitive type Number. // If both operands are of the Number primitive type, the result is of the Number primitive type. resultType = numberType; } else { - if (isTypeOfKind(leftType, TypeFlags.StringLike) || isTypeOfKind(rightType, TypeFlags.StringLike)) { + if (isTypeOfKind(leftType, TypeFlags.StringLike, /*excludeAny*/ true) || isTypeOfKind(rightType, TypeFlags.StringLike, /*excludeAny*/ true)) { // If one or both operands are of the String primitive type, the result is of the String primitive type. resultType = stringType; } else if (isTypeAny(leftType) || isTypeAny(rightType)) { // Otherwise, the result is of type Any. // NOTE: unknown type here denotes error type. Old compiler treated this case as any type so do we. + // TODO: Reorder this to check for any (plus void/undefined/null) first resultType = leftType === unknownType || rightType === unknownType ? unknownType : anyType; } @@ -20317,7 +20322,7 @@ namespace ts { // unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved // in this case error about missing name is already reported - do not report extra one - if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.Object | TypeFlags.TypeVariable | TypeFlags.NonPrimitive)) { + if (!isTypeOfKind(rightType, TypeFlags.NonPrimitive | TypeFlags.TypeVariable)) { error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } diff --git a/tests/baselines/reference/additionOperatorWithNullValueAndInvalidOperator.errors.txt b/tests/baselines/reference/additionOperatorWithNullValueAndInvalidOperator.errors.txt index 5f0d78c59d5a9..891fe86dcd162 100644 --- a/tests/baselines/reference/additionOperatorWithNullValueAndInvalidOperator.errors.txt +++ b/tests/baselines/reference/additionOperatorWithNullValueAndInvalidOperator.errors.txt @@ -1,14 +1,14 @@ -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(11,10): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(12,10): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(13,10): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(14,14): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(15,14): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(16,10): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(19,10): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(20,10): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(21,10): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(22,11): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(23,11): error TS2531: Object is possibly 'null'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(11,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'boolean'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(12,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'Object'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(13,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'void'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(14,10): error TS2365: Operator '+' cannot be applied to types 'boolean' and 'null'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(15,10): error TS2365: Operator '+' cannot be applied to types 'Object' and 'null'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(16,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'void'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(19,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'Number'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(20,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'true'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(21,10): error TS2365: Operator '+' cannot be applied to types 'null' and '{ a: string; }'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(22,11): error TS2365: Operator '+' cannot be applied to types 'null' and 'void'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts(23,11): error TS2365: Operator '+' cannot be applied to types 'null' and '() => void'. ==== tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndInvalidOperator.ts (11 errors) ==== @@ -23,37 +23,37 @@ tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOpe // null + boolean/Object var r1 = null + a; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'boolean'. var r2 = null + b; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'Object'. var r3 = null + c; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'void'. var r4 = a + null; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'boolean' and 'null'. var r5 = b + null; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'Object' and 'null'. var r6 = null + c; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'void'. // other cases var r7 = null + d; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'Number'. var r8 = null + true; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'true'. var r9 = null + { a: '' }; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and '{ a: string; }'. var r10 = null + foo(); - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'void'. var r11 = null + (() => { }); - ~~~~ -!!! error TS2531: Object is possibly 'null'. \ No newline at end of file + ~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and '() => void'. \ No newline at end of file diff --git a/tests/baselines/reference/additionOperatorWithNullValueAndValidOperator.errors.txt b/tests/baselines/reference/additionOperatorWithNullValueAndValidOperator.errors.txt index db01a42c8bddd..b722fd1be4654 100644 --- a/tests/baselines/reference/additionOperatorWithNullValueAndValidOperator.errors.txt +++ b/tests/baselines/reference/additionOperatorWithNullValueAndValidOperator.errors.txt @@ -1,13 +1,13 @@ -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(15,10): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(16,10): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(17,10): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(18,10): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(19,10): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(20,14): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(21,14): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(22,15): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(23,17): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(24,20): error TS2531: Object is possibly 'null'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(15,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'number'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(16,10): error TS2365: Operator '+' cannot be applied to types 'null' and '1'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(17,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'E'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(18,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'E.a'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(19,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'E.a'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(20,10): error TS2365: Operator '+' cannot be applied to types 'number' and 'null'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(21,10): error TS2365: Operator '+' cannot be applied to types '1' and 'null'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(22,11): error TS2365: Operator '+' cannot be applied to types 'E' and 'null'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(23,11): error TS2365: Operator '+' cannot be applied to types 'E.a' and 'null'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts(24,11): error TS2365: Operator '+' cannot be applied to types 'E.a' and 'null'. ==== tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithNullValueAndValidOperator.ts (10 errors) ==== @@ -26,35 +26,35 @@ tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOpe // null + number/enum var r3 = null + b; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'number'. var r4 = null + 1; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and '1'. var r5 = null + c; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'E'. var r6 = null + E.a; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'E.a'. var r7 = null + E['a']; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'E.a'. var r8 = b + null; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'number' and 'null'. var r9 = 1 + null; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types '1' and 'null'. var r10 = c + null - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'E' and 'null'. var r11 = E.a + null; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'E.a' and 'null'. var r12 = E['a'] + null; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'E.a' and 'null'. // null + string var r13 = null + d; diff --git a/tests/baselines/reference/additionOperatorWithOnlyNullValueOrUndefinedValue.errors.txt b/tests/baselines/reference/additionOperatorWithOnlyNullValueOrUndefinedValue.errors.txt index aef66891be072..b4746ff1e68b0 100644 --- a/tests/baselines/reference/additionOperatorWithOnlyNullValueOrUndefinedValue.errors.txt +++ b/tests/baselines/reference/additionOperatorWithOnlyNullValueOrUndefinedValue.errors.txt @@ -1,32 +1,20 @@ -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithOnlyNullValueOrUndefinedValue.ts(2,10): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithOnlyNullValueOrUndefinedValue.ts(2,17): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithOnlyNullValueOrUndefinedValue.ts(3,10): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithOnlyNullValueOrUndefinedValue.ts(3,17): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithOnlyNullValueOrUndefinedValue.ts(4,10): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithOnlyNullValueOrUndefinedValue.ts(4,22): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithOnlyNullValueOrUndefinedValue.ts(5,10): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithOnlyNullValueOrUndefinedValue.ts(5,22): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithOnlyNullValueOrUndefinedValue.ts(2,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithOnlyNullValueOrUndefinedValue.ts(3,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithOnlyNullValueOrUndefinedValue.ts(4,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'null'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithOnlyNullValueOrUndefinedValue.ts(5,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. -==== tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithOnlyNullValueOrUndefinedValue.ts (8 errors) ==== +==== tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithOnlyNullValueOrUndefinedValue.ts (4 errors) ==== // bug 819721 var r1 = null + null; - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. var r2 = null + undefined; - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. var r3 = undefined + null; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'null'. var r4 = undefined + undefined; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. \ No newline at end of file + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. \ No newline at end of file diff --git a/tests/baselines/reference/additionOperatorWithTypeParameter.errors.txt b/tests/baselines/reference/additionOperatorWithTypeParameter.errors.txt index 478c4fdee3f88..bdb81190b5098 100644 --- a/tests/baselines/reference/additionOperatorWithTypeParameter.errors.txt +++ b/tests/baselines/reference/additionOperatorWithTypeParameter.errors.txt @@ -8,8 +8,8 @@ tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOpe tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithTypeParameter.ts(27,15): error TS2365: Operator '+' cannot be applied to types 'Object' and 'T'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithTypeParameter.ts(28,15): error TS2365: Operator '+' cannot be applied to types 'E' and 'T'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithTypeParameter.ts(29,15): error TS2365: Operator '+' cannot be applied to types 'void' and 'T'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithTypeParameter.ts(32,19): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithTypeParameter.ts(33,19): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithTypeParameter.ts(32,15): error TS2365: Operator '+' cannot be applied to types 'T' and 'null'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithTypeParameter.ts(33,15): error TS2365: Operator '+' cannot be applied to types 'T' and 'undefined'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithTypeParameter.ts(34,15): error TS2365: Operator '+' cannot be applied to types 'T' and 'T'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithTypeParameter.ts(35,15): error TS2365: Operator '+' cannot be applied to types 'T' and 'U'. tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithTypeParameter.ts(36,15): error TS2365: Operator '+' cannot be applied to types 'T' and '() => void'. @@ -69,11 +69,11 @@ tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOpe // other cases var r15 = t + null; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'T' and 'null'. var r16 = t + undefined; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'T' and 'undefined'. var r17 = t + t; ~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'T' and 'T'. diff --git a/tests/baselines/reference/additionOperatorWithUndefinedValueAndInvalidOperands.errors.txt b/tests/baselines/reference/additionOperatorWithUndefinedValueAndInvalidOperands.errors.txt index 06e8c67b10568..6be41e81fd532 100644 --- a/tests/baselines/reference/additionOperatorWithUndefinedValueAndInvalidOperands.errors.txt +++ b/tests/baselines/reference/additionOperatorWithUndefinedValueAndInvalidOperands.errors.txt @@ -1,14 +1,14 @@ -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(11,10): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(12,10): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(13,10): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(14,14): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(15,14): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(16,10): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(19,10): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(20,10): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(21,10): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(22,11): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(23,11): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(11,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'boolean'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(12,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'Object'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(13,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'void'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(14,10): error TS2365: Operator '+' cannot be applied to types 'boolean' and 'undefined'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(15,10): error TS2365: Operator '+' cannot be applied to types 'Object' and 'undefined'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(16,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'void'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(19,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'Number'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(20,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'true'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(21,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and '{ a: string; }'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(22,11): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'void'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts(23,11): error TS2365: Operator '+' cannot be applied to types 'undefined' and '() => void'. ==== tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndInvalidOperands.ts (11 errors) ==== @@ -23,37 +23,37 @@ tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOpe // undefined + boolean/Object var r1 = undefined + a; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'boolean'. var r2 = undefined + b; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'Object'. var r3 = undefined + c; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'void'. var r4 = a + undefined; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'boolean' and 'undefined'. var r5 = b + undefined; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'Object' and 'undefined'. var r6 = undefined + c; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'void'. // other cases var r7 = undefined + d; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'Number'. var r8 = undefined + true; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'true'. var r9 = undefined + { a: '' }; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and '{ a: string; }'. var r10 = undefined + foo(); - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'void'. var r11 = undefined + (() => { }); - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. \ No newline at end of file + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and '() => void'. \ No newline at end of file diff --git a/tests/baselines/reference/additionOperatorWithUndefinedValueAndValidOperator.errors.txt b/tests/baselines/reference/additionOperatorWithUndefinedValueAndValidOperator.errors.txt index 04c0e2f3266e7..db2446aa3f9db 100644 --- a/tests/baselines/reference/additionOperatorWithUndefinedValueAndValidOperator.errors.txt +++ b/tests/baselines/reference/additionOperatorWithUndefinedValueAndValidOperator.errors.txt @@ -1,13 +1,13 @@ -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(15,10): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(16,10): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(17,10): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(18,10): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(19,10): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(20,14): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(21,14): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(22,15): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(23,17): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(24,20): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(15,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'number'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(16,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and '1'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(17,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'E'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(18,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'E.a'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(19,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'E.a'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(20,10): error TS2365: Operator '+' cannot be applied to types 'number' and 'undefined'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(21,10): error TS2365: Operator '+' cannot be applied to types '1' and 'undefined'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(22,11): error TS2365: Operator '+' cannot be applied to types 'E' and 'undefined'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(23,11): error TS2365: Operator '+' cannot be applied to types 'E.a' and 'undefined'. +tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts(24,11): error TS2365: Operator '+' cannot be applied to types 'E.a' and 'undefined'. ==== tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOperatorWithUndefinedValueAndValidOperator.ts (10 errors) ==== @@ -26,35 +26,35 @@ tests/cases/conformance/expressions/binaryOperators/additionOperator/additionOpe // undefined + number/enum var r3 = undefined + b; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'number'. var r4 = undefined + 1; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and '1'. var r5 = undefined + c; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'E'. var r6 = undefined + E.a; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'E.a'. var r7 = undefined + E['a']; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'E.a'. var r8 = b + undefined; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'number' and 'undefined'. var r9 = 1 + undefined; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types '1' and 'undefined'. var r10 = c + undefined - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'E' and 'undefined'. var r11 = E.a + undefined; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'E.a' and 'undefined'. var r12 = E['a'] + undefined; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'E.a' and 'undefined'. // undefined + string var r13 = undefined + d; diff --git a/tests/baselines/reference/bitwiseNotOperatorWithAnyOtherType.errors.txt b/tests/baselines/reference/bitwiseNotOperatorWithAnyOtherType.errors.txt index 411c7099f1149..795a9f0863dc1 100644 --- a/tests/baselines/reference/bitwiseNotOperatorWithAnyOtherType.errors.txt +++ b/tests/baselines/reference/bitwiseNotOperatorWithAnyOtherType.errors.txt @@ -1,14 +1,11 @@ tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithAnyOtherType.ts(34,24): error TS2532: Object is possibly 'undefined'. tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithAnyOtherType.ts(35,24): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithAnyOtherType.ts(46,26): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithAnyOtherType.ts(46,33): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithAnyOtherType.ts(47,26): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithAnyOtherType.ts(47,33): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithAnyOtherType.ts(48,26): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithAnyOtherType.ts(48,38): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithAnyOtherType.ts(46,26): error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. +tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithAnyOtherType.ts(47,26): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. +tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithAnyOtherType.ts(48,26): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. -==== tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithAnyOtherType.ts (8 errors) ==== +==== tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithAnyOtherType.ts (5 errors) ==== // ~ operator on any type var ANY: any; @@ -59,20 +56,14 @@ tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNot var ResultIsNumber14 = ~A.foo(); var ResultIsNumber15 = ~(ANY + ANY1); var ResultIsNumber16 = ~(null + undefined); - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. var ResultIsNumber17 = ~(null + null); - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. var ResultIsNumber18 = ~(undefined + undefined); - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. // multiple ~ operators var ResultIsNumber19 = ~~ANY; diff --git a/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.errors.txt b/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.errors.txt index 08d8fd0c6d3f7..f7df532b20ed9 100644 --- a/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.errors.txt +++ b/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentLHSCanBeAssigned.ts(32,7): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentLHSCanBeAssigned.ts(33,7): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentLHSCanBeAssigned.ts(39,7): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentLHSCanBeAssigned.ts(40,7): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentLHSCanBeAssigned.ts(32,1): error TS2365: Operator '+=' cannot be applied to types 'number' and 'null'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentLHSCanBeAssigned.ts(33,1): error TS2365: Operator '+=' cannot be applied to types 'number' and 'undefined'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentLHSCanBeAssigned.ts(39,1): error TS2365: Operator '+=' cannot be applied to types 'E' and 'null'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentLHSCanBeAssigned.ts(40,1): error TS2365: Operator '+=' cannot be applied to types 'E' and 'undefined'. ==== tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentLHSCanBeAssigned.ts (4 errors) ==== @@ -37,22 +37,22 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmen x3 += 0; x3 += E.a; x3 += null; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~ +!!! error TS2365: Operator '+=' cannot be applied to types 'number' and 'null'. x3 += undefined; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+=' cannot be applied to types 'number' and 'undefined'. var x4: E; x4 += a; x4 += 0; x4 += E.a; x4 += null; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~ +!!! error TS2365: Operator '+=' cannot be applied to types 'E' and 'null'. x4 += undefined; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+=' cannot be applied to types 'E' and 'undefined'. var x5: boolean; x5 += a; diff --git a/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.errors.txt b/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.errors.txt index 1812065f149ca..e570f2f6cf0ef 100644 --- a/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.errors.txt +++ b/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.errors.txt @@ -3,22 +3,22 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmen tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(8,1): error TS2365: Operator '+=' cannot be applied to types 'boolean' and '0'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(9,1): error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'E.a'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(10,1): error TS2365: Operator '+=' cannot be applied to types 'boolean' and '{}'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(11,7): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(12,7): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(11,1): error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'null'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(12,1): error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'undefined'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(15,1): error TS2365: Operator '+=' cannot be applied to types '{}' and 'void'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(16,1): error TS2365: Operator '+=' cannot be applied to types '{}' and 'true'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(17,1): error TS2365: Operator '+=' cannot be applied to types '{}' and '0'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(18,1): error TS2365: Operator '+=' cannot be applied to types '{}' and 'E.a'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(19,1): error TS2365: Operator '+=' cannot be applied to types '{}' and '{}'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(20,7): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(21,7): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(20,1): error TS2365: Operator '+=' cannot be applied to types '{}' and 'null'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(21,1): error TS2365: Operator '+=' cannot be applied to types '{}' and 'undefined'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(24,1): error TS2365: Operator '+=' cannot be applied to types 'void' and 'void'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(25,1): error TS2365: Operator '+=' cannot be applied to types 'void' and 'true'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(26,1): error TS2365: Operator '+=' cannot be applied to types 'void' and '0'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(27,1): error TS2365: Operator '+=' cannot be applied to types 'void' and 'E.a'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(28,1): error TS2365: Operator '+=' cannot be applied to types 'void' and '{}'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(29,7): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(30,7): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(29,1): error TS2365: Operator '+=' cannot be applied to types 'void' and 'null'. +tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(30,1): error TS2365: Operator '+=' cannot be applied to types 'void' and 'undefined'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(33,1): error TS2365: Operator '+=' cannot be applied to types 'number' and 'void'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(34,1): error TS2365: Operator '+=' cannot be applied to types 'number' and 'true'. tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentWithInvalidOperands.ts(35,1): error TS2365: Operator '+=' cannot be applied to types 'number' and '{}'. @@ -49,11 +49,11 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmen ~~~~~~~~ !!! error TS2365: Operator '+=' cannot be applied to types 'boolean' and '{}'. x1 += null; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~ +!!! error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'null'. x1 += undefined; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+=' cannot be applied to types 'boolean' and 'undefined'. var x2: {}; x2 += a; @@ -72,11 +72,11 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmen ~~~~~~~~ !!! error TS2365: Operator '+=' cannot be applied to types '{}' and '{}'. x2 += null; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~ +!!! error TS2365: Operator '+=' cannot be applied to types '{}' and 'null'. x2 += undefined; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+=' cannot be applied to types '{}' and 'undefined'. var x3: void; x3 += a; @@ -95,11 +95,11 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmen ~~~~~~~~ !!! error TS2365: Operator '+=' cannot be applied to types 'void' and '{}'. x3 += null; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~ +!!! error TS2365: Operator '+=' cannot be applied to types 'void' and 'null'. x3 += undefined; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+=' cannot be applied to types 'void' and 'undefined'. var x4: number; x4 += a; diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt index 33e31bc947861..ff54b4d52c6fb 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt @@ -19,27 +19,21 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(46,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(47,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(48,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(48,27): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(48,34): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(48,27): error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(49,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(49,27): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(49,34): error TS2531: Object is possibly 'null'. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(49,27): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(50,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(50,27): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(50,39): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(50,27): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(51,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(52,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(54,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(55,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(56,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(56,25): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(56,32): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(56,25): error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(57,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(57,25): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(57,32): error TS2531: Object is possibly 'null'. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(57,25): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(58,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(58,25): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(58,37): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(58,25): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(59,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(60,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(63,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -58,7 +52,7 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(72,12): error TS1109: Expression expected. -==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts (58 errors) ==== +==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts (52 errors) ==== // -- operator on any type var ANY1: any; var ANY2: any[] = ["", ""]; @@ -149,24 +143,18 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp var ResultIsNumber19 = --(null + undefined); ~~~~~~~~~~~~~~~~~~ !!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. var ResultIsNumber20 = --(null + null); ~~~~~~~~~~~~~ !!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. var ResultIsNumber21 = --(undefined + undefined); ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber22 = --obj1.x; ~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -183,24 +171,18 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp var ResultIsNumber26 = (null + undefined)--; ~~~~~~~~~~~~~~~~~~ !!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. var ResultIsNumber27 = (null + null)--; ~~~~~~~~~~~~~ !!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. var ResultIsNumber28 = (undefined + undefined)--; ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber29 = obj1.x--; ~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. diff --git a/tests/baselines/reference/deleteOperatorWithAnyOtherType.errors.txt b/tests/baselines/reference/deleteOperatorWithAnyOtherType.errors.txt index f2260b110365a..5ea3f6135c16c 100644 --- a/tests/baselines/reference/deleteOperatorWithAnyOtherType.errors.txt +++ b/tests/baselines/reference/deleteOperatorWithAnyOtherType.errors.txt @@ -9,15 +9,12 @@ tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperator tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(42,32): error TS2703: The operand of a delete operator must be a property reference. tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(43,32): error TS2703: The operand of a delete operator must be a property reference. tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(44,33): error TS2703: The operand of a delete operator must be a property reference. -tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(45,33): error TS2531: Object is possibly 'null'. +tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(45,33): error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(45,33): error TS2703: The operand of a delete operator must be a property reference. -tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(45,40): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(46,33): error TS2531: Object is possibly 'null'. +tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(46,33): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(46,33): error TS2703: The operand of a delete operator must be a property reference. -tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(46,40): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(47,33): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(47,33): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(47,33): error TS2703: The operand of a delete operator must be a property reference. -tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(47,45): error TS2532: Object is possibly 'undefined'. tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(50,32): error TS2703: The operand of a delete operator must be a property reference. tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(50,39): error TS2703: The operand of a delete operator must be a property reference. tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(51,32): error TS2703: The operand of a delete operator must be a property reference. @@ -28,7 +25,7 @@ tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperator tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts(57,8): error TS2703: The operand of a delete operator must be a property reference. -==== tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts (28 errors) ==== +==== tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithAnyOtherType.ts (25 errors) ==== // delete operator on any type var ANY: any; @@ -96,26 +93,20 @@ tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperator ~~~~~~~~~~ !!! error TS2703: The operand of a delete operator must be a property reference. var ResultIsBoolean17 = delete (null + undefined); - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. ~~~~~~~~~~~~~~~~ !!! error TS2703: The operand of a delete operator must be a property reference. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. var ResultIsBoolean18 = delete (null + null); - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. ~~~~~~~~~~~ !!! error TS2703: The operand of a delete operator must be a property reference. - ~~~~ -!!! error TS2531: Object is possibly 'null'. var ResultIsBoolean19 = delete (undefined + undefined); - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2703: The operand of a delete operator must be a property reference. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. // multiple delete operators var ResultIsBoolean20 = delete delete ANY; diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt index afdddab86a7ec..690f3391933d7 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt @@ -19,27 +19,21 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(46,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(47,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(48,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(48,27): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(48,34): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(48,27): error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(49,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(49,27): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(49,34): error TS2531: Object is possibly 'null'. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(49,27): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(50,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(50,27): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(50,39): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(50,27): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(51,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(52,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(54,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(55,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(56,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(56,25): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(56,32): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(56,25): error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(57,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(57,25): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(57,32): error TS2531: Object is possibly 'null'. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(57,25): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(58,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(58,25): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(58,37): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(58,25): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(59,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(60,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(63,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -53,7 +47,7 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(69,12): error TS1109: Expression expected. -==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts (53 errors) ==== +==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts (47 errors) ==== // ++ operator on any type var ANY1: any; var ANY2: any[] = [1, 2]; @@ -144,24 +138,18 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp var ResultIsNumber19 = ++(null + undefined); ~~~~~~~~~~~~~~~~~~ !!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. var ResultIsNumber20 = ++(null + null); ~~~~~~~~~~~~~ !!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. var ResultIsNumber21 = ++(undefined + undefined); ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber22 = ++obj1.x; ~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -178,24 +166,18 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp var ResultIsNumber26 = (null + undefined)++; ~~~~~~~~~~~~~~~~~~ !!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. var ResultIsNumber27 = (null + null)++; ~~~~~~~~~~~~~ !!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. var ResultIsNumber28 = (undefined + undefined)++; ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber29 = obj1.x++; ~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. diff --git a/tests/baselines/reference/logicalNotOperatorWithAnyOtherType.errors.txt b/tests/baselines/reference/logicalNotOperatorWithAnyOtherType.errors.txt index 0cb9869ca4cc3..ad951adf5f7e4 100644 --- a/tests/baselines/reference/logicalNotOperatorWithAnyOtherType.errors.txt +++ b/tests/baselines/reference/logicalNotOperatorWithAnyOtherType.errors.txt @@ -1,13 +1,10 @@ -tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithAnyOtherType.ts(45,27): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithAnyOtherType.ts(45,34): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithAnyOtherType.ts(46,27): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithAnyOtherType.ts(46,34): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithAnyOtherType.ts(47,27): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithAnyOtherType.ts(47,39): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithAnyOtherType.ts(45,27): error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. +tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithAnyOtherType.ts(46,27): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. +tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithAnyOtherType.ts(47,27): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithAnyOtherType.ts(57,1): error TS2695: Left side of comma operator is unused and has no side effects. -==== tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithAnyOtherType.ts (7 errors) ==== +==== tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithAnyOtherType.ts (4 errors) ==== // ! operator on any type var ANY: any; @@ -53,20 +50,14 @@ tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNot var ResultIsBoolean15 = !A.foo(); var ResultIsBoolean16 = !(ANY + ANY1); var ResultIsBoolean17 = !(null + undefined); - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. var ResultIsBoolean18 = !(null + null); - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. var ResultIsBoolean19 = !(undefined + undefined); - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. // multiple ! operators var ResultIsBoolean20 = !!ANY; diff --git a/tests/baselines/reference/null.errors.txt b/tests/baselines/reference/null.errors.txt index 6b05bfb94d12d..ed6db12d99b66 100644 --- a/tests/baselines/reference/null.errors.txt +++ b/tests/baselines/reference/null.errors.txt @@ -1,12 +1,12 @@ -tests/cases/compiler/null.ts(3,9): error TS2531: Object is possibly 'null'. +tests/cases/compiler/null.ts(3,7): error TS2365: Operator '+' cannot be applied to types '3' and 'null'. ==== tests/cases/compiler/null.ts (1 errors) ==== var x=null; var y=3+x; var z=3+null; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types '3' and 'null'. class C { } function f() { diff --git a/tests/baselines/reference/operatorAddNullUndefined.errors.txt b/tests/baselines/reference/operatorAddNullUndefined.errors.txt index 871ef3fc98f47..c6a74080394e0 100644 --- a/tests/baselines/reference/operatorAddNullUndefined.errors.txt +++ b/tests/baselines/reference/operatorAddNullUndefined.errors.txt @@ -1,68 +1,56 @@ -tests/cases/compiler/operatorAddNullUndefined.ts(2,10): error TS2531: Object is possibly 'null'. -tests/cases/compiler/operatorAddNullUndefined.ts(2,17): error TS2531: Object is possibly 'null'. -tests/cases/compiler/operatorAddNullUndefined.ts(3,10): error TS2531: Object is possibly 'null'. -tests/cases/compiler/operatorAddNullUndefined.ts(3,17): error TS2532: Object is possibly 'undefined'. -tests/cases/compiler/operatorAddNullUndefined.ts(4,10): error TS2532: Object is possibly 'undefined'. -tests/cases/compiler/operatorAddNullUndefined.ts(4,22): error TS2531: Object is possibly 'null'. -tests/cases/compiler/operatorAddNullUndefined.ts(5,10): error TS2532: Object is possibly 'undefined'. -tests/cases/compiler/operatorAddNullUndefined.ts(5,22): error TS2532: Object is possibly 'undefined'. -tests/cases/compiler/operatorAddNullUndefined.ts(6,14): error TS2531: Object is possibly 'null'. -tests/cases/compiler/operatorAddNullUndefined.ts(7,14): error TS2532: Object is possibly 'undefined'. -tests/cases/compiler/operatorAddNullUndefined.ts(8,10): error TS2531: Object is possibly 'null'. -tests/cases/compiler/operatorAddNullUndefined.ts(9,10): error TS2532: Object is possibly 'undefined'. -tests/cases/compiler/operatorAddNullUndefined.ts(14,11): error TS2531: Object is possibly 'null'. -tests/cases/compiler/operatorAddNullUndefined.ts(15,11): error TS2532: Object is possibly 'undefined'. -tests/cases/compiler/operatorAddNullUndefined.ts(16,17): error TS2531: Object is possibly 'null'. -tests/cases/compiler/operatorAddNullUndefined.ts(17,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/operatorAddNullUndefined.ts(2,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. +tests/cases/compiler/operatorAddNullUndefined.ts(3,10): error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. +tests/cases/compiler/operatorAddNullUndefined.ts(4,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'null'. +tests/cases/compiler/operatorAddNullUndefined.ts(5,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. +tests/cases/compiler/operatorAddNullUndefined.ts(6,10): error TS2365: Operator '+' cannot be applied to types '1' and 'null'. +tests/cases/compiler/operatorAddNullUndefined.ts(7,10): error TS2365: Operator '+' cannot be applied to types '1' and 'undefined'. +tests/cases/compiler/operatorAddNullUndefined.ts(8,10): error TS2365: Operator '+' cannot be applied to types 'null' and '1'. +tests/cases/compiler/operatorAddNullUndefined.ts(9,10): error TS2365: Operator '+' cannot be applied to types 'undefined' and '1'. +tests/cases/compiler/operatorAddNullUndefined.ts(14,11): error TS2365: Operator '+' cannot be applied to types 'null' and 'E'. +tests/cases/compiler/operatorAddNullUndefined.ts(15,11): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'E'. +tests/cases/compiler/operatorAddNullUndefined.ts(16,11): error TS2365: Operator '+' cannot be applied to types 'E' and 'null'. +tests/cases/compiler/operatorAddNullUndefined.ts(17,11): error TS2365: Operator '+' cannot be applied to types 'E' and 'undefined'. -==== tests/cases/compiler/operatorAddNullUndefined.ts (16 errors) ==== +==== tests/cases/compiler/operatorAddNullUndefined.ts (12 errors) ==== enum E { x } var x1 = null + null; - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. var x2 = null + undefined; - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. var x3 = undefined + null; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'null'. var x4 = undefined + undefined; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var x5 = 1 + null; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types '1' and 'null'. var x6 = 1 + undefined; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types '1' and 'undefined'. var x7 = null + 1; - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and '1'. var x8 = undefined + 1; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and '1'. var x9 = "test" + null; var x10 = "test" + undefined; var x11 = null + "test"; var x12 = undefined + "test"; var x13 = null + E.x - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'E'. var x14 = undefined + E.x - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'E'. var x15 = E.x + null - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'E' and 'null'. var x16 = E.x + undefined - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. \ No newline at end of file + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'E' and 'undefined'. \ No newline at end of file diff --git a/tests/baselines/reference/plusOperatorWithAnyOtherType.errors.txt b/tests/baselines/reference/plusOperatorWithAnyOtherType.errors.txt index d693aaa17d96c..561215bbd9593 100644 --- a/tests/baselines/reference/plusOperatorWithAnyOtherType.errors.txt +++ b/tests/baselines/reference/plusOperatorWithAnyOtherType.errors.txt @@ -1,15 +1,12 @@ tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithAnyOtherType.ts(34,24): error TS2532: Object is possibly 'undefined'. tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithAnyOtherType.ts(35,24): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithAnyOtherType.ts(46,26): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithAnyOtherType.ts(46,33): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithAnyOtherType.ts(47,26): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithAnyOtherType.ts(47,33): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithAnyOtherType.ts(48,26): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithAnyOtherType.ts(48,38): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithAnyOtherType.ts(46,26): error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. +tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithAnyOtherType.ts(47,26): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. +tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithAnyOtherType.ts(48,26): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithAnyOtherType.ts(54,1): error TS2695: Left side of comma operator is unused and has no side effects. -==== tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithAnyOtherType.ts (9 errors) ==== +==== tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithAnyOtherType.ts (6 errors) ==== // + operator on any type var ANY: any; @@ -60,20 +57,14 @@ tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWith var ResultIsNumber15 = +A.foo(); var ResultIsNumber16 = +(ANY + ANY1); var ResultIsNumber17 = +(null + undefined); - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. var ResultIsNumber18 = +(null + null); - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. var ResultIsNumber19 = +(undefined + undefined); - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. // miss assignment operators +ANY; diff --git a/tests/baselines/reference/typeParamExtendsNumber.js b/tests/baselines/reference/typeParamExtendsNumber.js new file mode 100644 index 0000000000000..70548e7985610 --- /dev/null +++ b/tests/baselines/reference/typeParamExtendsNumber.js @@ -0,0 +1,19 @@ +//// [typeParamExtendsNumber.ts] +function f() { + var t: T; + var v = { + [t]: 0 + } + return t + t; +} + + +//// [typeParamExtendsNumber.js] +function f() { + var t; + var v = (_a = {}, + _a[t] = 0, + _a); + return t + t; + var _a; +} diff --git a/tests/baselines/reference/typeParamExtendsNumber.symbols b/tests/baselines/reference/typeParamExtendsNumber.symbols new file mode 100644 index 0000000000000..032f08bd58c26 --- /dev/null +++ b/tests/baselines/reference/typeParamExtendsNumber.symbols @@ -0,0 +1,20 @@ +=== tests/cases/compiler/typeParamExtendsNumber.ts === +function f() { +>f : Symbol(f, Decl(typeParamExtendsNumber.ts, 0, 0)) +>T : Symbol(T, Decl(typeParamExtendsNumber.ts, 0, 11)) + + var t: T; +>t : Symbol(t, Decl(typeParamExtendsNumber.ts, 1, 7)) +>T : Symbol(T, Decl(typeParamExtendsNumber.ts, 0, 11)) + + var v = { +>v : Symbol(v, Decl(typeParamExtendsNumber.ts, 2, 7)) + + [t]: 0 +>t : Symbol(t, Decl(typeParamExtendsNumber.ts, 1, 7)) + } + return t + t; +>t : Symbol(t, Decl(typeParamExtendsNumber.ts, 1, 7)) +>t : Symbol(t, Decl(typeParamExtendsNumber.ts, 1, 7)) +} + diff --git a/tests/baselines/reference/typeParamExtendsNumber.types b/tests/baselines/reference/typeParamExtendsNumber.types new file mode 100644 index 0000000000000..9034e23ee23d4 --- /dev/null +++ b/tests/baselines/reference/typeParamExtendsNumber.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/typeParamExtendsNumber.ts === +function f() { +>f : () => number +>T : T + + var t: T; +>t : T +>T : T + + var v = { +>v : { [x: number]: number; } +>{ [t]: 0 } : { [x: number]: number; } + + [t]: 0 +>t : T +>0 : 0 + } + return t + t; +>t + t : number +>t : T +>t : T +} + diff --git a/tests/baselines/reference/typeofOperatorWithAnyOtherType.errors.txt b/tests/baselines/reference/typeofOperatorWithAnyOtherType.errors.txt index 3680b1be60fe8..9357cf4e4cc36 100644 --- a/tests/baselines/reference/typeofOperatorWithAnyOtherType.errors.txt +++ b/tests/baselines/reference/typeofOperatorWithAnyOtherType.errors.txt @@ -1,9 +1,6 @@ -tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithAnyOtherType.ts(46,32): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithAnyOtherType.ts(46,39): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithAnyOtherType.ts(47,32): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithAnyOtherType.ts(47,39): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithAnyOtherType.ts(48,32): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithAnyOtherType.ts(48,44): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithAnyOtherType.ts(46,32): error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. +tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithAnyOtherType.ts(47,32): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. +tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithAnyOtherType.ts(48,32): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithAnyOtherType.ts(58,1): error TS2695: Left side of comma operator is unused and has no side effects. tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithAnyOtherType.ts(68,1): error TS7028: Unused label. tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithAnyOtherType.ts(69,1): error TS7028: Unused label. @@ -14,7 +11,7 @@ tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperator tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithAnyOtherType.ts(74,1): error TS7028: Unused label. -==== tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithAnyOtherType.ts (14 errors) ==== +==== tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithAnyOtherType.ts (11 errors) ==== // typeof operator on any type var ANY: any; @@ -61,20 +58,14 @@ tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperator var ResultIsString15 = typeof A.foo(); var ResultIsString16 = typeof (ANY + ANY1); var ResultIsString17 = typeof (null + undefined); - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. var ResultIsString18 = typeof (null + null); - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. var ResultIsString19 = typeof (undefined + undefined); - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. // multiple typeof operators var ResultIsString20 = typeof typeof ANY; diff --git a/tests/baselines/reference/voidOperatorWithAnyOtherType.errors.txt b/tests/baselines/reference/voidOperatorWithAnyOtherType.errors.txt index 5867a7ad6f5d2..7230f90c4f392 100644 --- a/tests/baselines/reference/voidOperatorWithAnyOtherType.errors.txt +++ b/tests/baselines/reference/voidOperatorWithAnyOtherType.errors.txt @@ -1,12 +1,9 @@ -tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWithAnyOtherType.ts(46,27): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWithAnyOtherType.ts(46,34): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWithAnyOtherType.ts(47,27): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWithAnyOtherType.ts(47,34): error TS2531: Object is possibly 'null'. -tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWithAnyOtherType.ts(48,27): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWithAnyOtherType.ts(48,39): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWithAnyOtherType.ts(46,27): error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. +tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWithAnyOtherType.ts(47,27): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. +tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWithAnyOtherType.ts(48,27): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. -==== tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWithAnyOtherType.ts (6 errors) ==== +==== tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWithAnyOtherType.ts (3 errors) ==== // void operator on any type var ANY: any; @@ -53,20 +50,14 @@ tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWith var ResultIsAny15 = void A.foo(); var ResultIsAny16 = void (ANY + ANY1); var ResultIsAny17 = void (null + undefined); - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. var ResultIsAny18 = void (null + null); - ~~~~ -!!! error TS2531: Object is possibly 'null'. - ~~~~ -!!! error TS2531: Object is possibly 'null'. + ~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. var ResultIsAny19 = void (undefined + undefined); - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. // multiple void operators var ResultIsAny20 = void void ANY; diff --git a/tests/cases/compiler/typeParamExtendsNumber.ts b/tests/cases/compiler/typeParamExtendsNumber.ts new file mode 100644 index 0000000000000..89b60c990a245 --- /dev/null +++ b/tests/cases/compiler/typeParamExtendsNumber.ts @@ -0,0 +1,7 @@ +function f() { + var t: T; + var v = { + [t]: 0 + } + return t + t; +} From d07eca72a36bd4031b54b238698f23fa6590a155 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 2 Aug 2017 09:38:44 -0700 Subject: [PATCH 4/8] Improve name:isTypeAssignableToKind+cleanup TODOs --- src/compiler/checker.ts | 68 +++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d1c18ef61d807..419a93994e60c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7526,11 +7526,11 @@ namespace ts { return getTypeOfSymbol(prop); } } - if (!(indexType.flags & TypeFlags.Nullable) && isTypeOfKind(indexType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { + if (!(indexType.flags & TypeFlags.Nullable) && isTypeAssignableToKind(indexType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { if (isTypeAny(objectType)) { return anyType; } - const indexInfo = isTypeOfKind(indexType, TypeFlags.NumberLike) && getIndexInfoOfType(objectType, IndexKind.Number) || + const indexInfo = isTypeAssignableToKind(indexType, TypeFlags.NumberLike) && getIndexInfoOfType(objectType, IndexKind.Number) || getIndexInfoOfType(objectType, IndexKind.String) || undefined; if (indexInfo) { @@ -11286,7 +11286,7 @@ namespace ts { (parent.parent).operatorToken.kind === SyntaxKind.EqualsToken && (parent.parent).left === parent && !isAssignmentTarget(parent.parent) && - isTypeOfKind(getTypeOfExpression((parent).argumentExpression), TypeFlags.NumberLike); + isTypeAssignableToKind(getTypeOfExpression((parent).argumentExpression), TypeFlags.NumberLike); return isLengthPushOrUnshift || isElementAssignment; } @@ -11458,7 +11458,7 @@ namespace ts { } else { const indexType = getTypeOfExpression(((node).left).argumentExpression); - if (isTypeOfKind(indexType, TypeFlags.NumberLike)) { + if (isTypeAssignableToKind(indexType, TypeFlags.NumberLike)) { evolvedType = addEvolvingArrayElementType(evolvedType, (node).right); } } @@ -13290,7 +13290,7 @@ namespace ts { function isNumericComputedName(name: ComputedPropertyName): boolean { // It seems odd to consider an expression of type Any to result in a numeric name, // but this behavior is consistent with checkIndexedAccess - return isTypeOfKind(checkComputedPropertyName(name), TypeFlags.NumberLike); + return isTypeAssignableToKind(checkComputedPropertyName(name), TypeFlags.NumberLike); } function isInfinityOrNaNString(name: string | __String): boolean { @@ -13328,7 +13328,7 @@ namespace ts { links.resolvedType = checkExpression(node.expression); // This will allow types number, string, symbol or any. It will also allow enums, the unknown // type, and any union of these types (like string | number). - if (links.resolvedType.flags & TypeFlags.Nullable || !isTypeOfKind(links.resolvedType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { + if (links.resolvedType.flags & TypeFlags.Nullable || !isTypeAssignableToKind(links.resolvedType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); } else { @@ -15431,7 +15431,7 @@ namespace ts { case SyntaxKind.ComputedPropertyName: const nameType = checkComputedPropertyName(element.name); - if (isTypeOfKind(nameType, TypeFlags.ESSymbol)) { + if (isTypeAssignableToKind(nameType, TypeFlags.ESSymbol)) { return nameType; } else { @@ -16813,7 +16813,7 @@ namespace ts { } function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage): boolean { - if (!isTypeOfKind(type, TypeFlags.NumberLike)) { + if (!isTypeAssignableToKind(type, TypeFlags.NumberLike)) { error(operand, diagnostic); return false; } @@ -16986,12 +16986,11 @@ namespace ts { return false; } - function isTypeOfKind(source: Type, kind: TypeFlags, excludeAny?: boolean) { + function isTypeAssignableToKind(source: Type, kind: TypeFlags, strict?: boolean) { if (source.flags & kind) { return true; } - if (excludeAny && source.flags & (TypeFlags.Any | TypeFlags.Void | TypeFlags.Undefined | TypeFlags.Null)) { - // TODO: The callers who want this should really handle these cases FIRST + if (strict && source.flags & (TypeFlags.Any | TypeFlags.Void | TypeFlags.Undefined | TypeFlags.Null)) { return false; } const targets = []; @@ -17042,7 +17041,7 @@ namespace ts { // and the right operand to be of type Any, a subtype of the 'Function' interface type, or have a call or construct signature. // The result is always of the Boolean primitive type. // NOTE: do not raise error if leftType is unknown as related error was already reported - if (isTypeOfKind(leftType, TypeFlags.Primitive, /*excludeAny*/ true)) { + if (!(leftType.flags & TypeFlags.Any) && isTypeAssignableToKind(leftType, TypeFlags.Primitive)) { error(left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported @@ -17065,10 +17064,10 @@ namespace ts { // The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type, // and the right operand to be of type Any, an object type, or a type parameter type. // The result is always of the Boolean primitive type. - if (!(isTypeComparableTo(leftType, stringType) || isTypeOfKind(leftType, TypeFlags.NumberLike | TypeFlags.ESSymbol))) { + if (!(isTypeComparableTo(leftType, stringType) || isTypeAssignableToKind(leftType, TypeFlags.NumberLike | TypeFlags.ESSymbol))) { error(left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } - if (!isTypeOfKind(rightType, TypeFlags.NonPrimitive | TypeFlags.TypeVariable)) { + if (!isTypeAssignableToKind(rightType, TypeFlags.NonPrimitive | TypeFlags.TypeVariable)) { error(right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -17377,33 +17376,30 @@ namespace ts { return silentNeverType; } - if (!isTypeOfKind(leftType, TypeFlags.StringLike) && !isTypeOfKind(rightType, TypeFlags.StringLike)) { + if (!isTypeAssignableToKind(leftType, TypeFlags.StringLike) && !isTypeAssignableToKind(rightType, TypeFlags.StringLike)) { leftType = checkNonNullType(leftType, left); rightType = checkNonNullType(rightType, right); } let resultType: Type; - if (isTypeOfKind(leftType, TypeFlags.NumberLike, /*excludeAny*/ true) && isTypeOfKind(rightType, TypeFlags.NumberLike, /*excludeAny*/ true)) { + if (isTypeAssignableToKind(leftType, TypeFlags.NumberLike, /*strict*/ true) && isTypeAssignableToKind(rightType, TypeFlags.NumberLike, /*strict*/ true)) { // Operands of an enum type are treated as having the primitive type Number. // If both operands are of the Number primitive type, the result is of the Number primitive type. resultType = numberType; } - else { - if (isTypeOfKind(leftType, TypeFlags.StringLike, /*excludeAny*/ true) || isTypeOfKind(rightType, TypeFlags.StringLike, /*excludeAny*/ true)) { + else if (isTypeAssignableToKind(leftType, TypeFlags.StringLike, /*strict*/ true) || isTypeAssignableToKind(rightType, TypeFlags.StringLike, /*strict*/ true)) { // If one or both operands are of the String primitive type, the result is of the String primitive type. resultType = stringType; - } - else if (isTypeAny(leftType) || isTypeAny(rightType)) { - // Otherwise, the result is of type Any. - // NOTE: unknown type here denotes error type. Old compiler treated this case as any type so do we. - // TODO: Reorder this to check for any (plus void/undefined/null) first - resultType = leftType === unknownType || rightType === unknownType ? unknownType : anyType; - } + } + else if (isTypeAny(leftType) || isTypeAny(rightType)) { + // Otherwise, the result is of type Any. + // NOTE: unknown type here denotes error type. Old compiler treated this case as any type so do we. + resultType = leftType === unknownType || rightType === unknownType ? unknownType : anyType; + } - // Symbols are not allowed at all in arithmetic expressions - if (resultType && !checkForDisallowedESSymbolOperand(operator)) { - return resultType; - } + // Symbols are not allowed at all in arithmetic expressions + if (resultType && !checkForDisallowedESSymbolOperand(operator)) { + return resultType; } if (!resultType) { @@ -18620,7 +18616,7 @@ namespace ts { } // Check if we're indexing with a numeric type and the object type is a generic // type with a constraint that has a numeric index signature. - if (maybeTypeOfKind(objectType, TypeFlags.TypeVariable) && isTypeOfKind(indexType, TypeFlags.NumberLike)) { + if (maybeTypeOfKind(objectType, TypeFlags.TypeVariable) && isTypeAssignableToKind(indexType, TypeFlags.NumberLike)) { const constraint = getBaseConstraintOfType(objectType); if (constraint && getIndexInfoOfType(constraint, IndexKind.Number)) { return type; @@ -20322,7 +20318,7 @@ namespace ts { // unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved // in this case error about missing name is already reported - do not report extra one - if (!isTypeOfKind(rightType, TypeFlags.NonPrimitive | TypeFlags.TypeVariable)) { + if (!isTypeAssignableToKind(rightType, TypeFlags.NonPrimitive | TypeFlags.TypeVariable)) { error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } @@ -23303,22 +23299,22 @@ namespace ts { else if (type.flags & TypeFlags.Any) { return TypeReferenceSerializationKind.ObjectType; } - else if (isTypeOfKind(type, TypeFlags.Void | TypeFlags.Nullable | TypeFlags.Never)) { + else if (isTypeAssignableToKind(type, TypeFlags.Void | TypeFlags.Nullable | TypeFlags.Never)) { return TypeReferenceSerializationKind.VoidNullableOrNeverType; } - else if (isTypeOfKind(type, TypeFlags.BooleanLike)) { + else if (isTypeAssignableToKind(type, TypeFlags.BooleanLike)) { return TypeReferenceSerializationKind.BooleanType; } - else if (isTypeOfKind(type, TypeFlags.NumberLike)) { + else if (isTypeAssignableToKind(type, TypeFlags.NumberLike)) { return TypeReferenceSerializationKind.NumberLikeType; } - else if (isTypeOfKind(type, TypeFlags.StringLike)) { + else if (isTypeAssignableToKind(type, TypeFlags.StringLike)) { return TypeReferenceSerializationKind.StringLikeType; } else if (isTupleType(type)) { return TypeReferenceSerializationKind.ArrayLikeType; } - else if (isTypeOfKind(type, TypeFlags.ESSymbol)) { + else if (isTypeAssignableToKind(type, TypeFlags.ESSymbol)) { return TypeReferenceSerializationKind.ESSymbolType; } else if (isFunctionType(type)) { From 011f712d980305c990c237dd46e9a9e1c1f2ce4c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 2 Aug 2017 09:58:01 -0700 Subject: [PATCH 5/8] isTypeAssignableToKind:Chain isTypeAssignableTo calls Instead of building up a list and creating a union type. --- src/compiler/checker.ts | 44 ++++++++++++----------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 419a93994e60c..e67ee72ffcac4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13328,7 +13328,9 @@ namespace ts { links.resolvedType = checkExpression(node.expression); // This will allow types number, string, symbol or any. It will also allow enums, the unknown // type, and any union of these types (like string | number). - if (links.resolvedType.flags & TypeFlags.Nullable || !isTypeAssignableToKind(links.resolvedType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { + if (links.resolvedType.flags & TypeFlags.Nullable || + !isTypeAssignableToKind(links.resolvedType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol) && + !isTypeAssignableTo(links.resolvedType, getUnionType([stringType, numberType, esSymbolType]))) { error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); } else { @@ -16986,42 +16988,22 @@ namespace ts { return false; } - function isTypeAssignableToKind(source: Type, kind: TypeFlags, strict?: boolean) { + function isTypeAssignableToKind(source: Type, kind: TypeFlags, strict?: boolean): boolean { if (source.flags & kind) { return true; } if (strict && source.flags & (TypeFlags.Any | TypeFlags.Void | TypeFlags.Undefined | TypeFlags.Null)) { return false; } - const targets = []; - if (kind & TypeFlags.NumberLike) { - targets.push(numberType); - } - if (kind & TypeFlags.StringLike) { - targets.push(stringType); - } - if (kind & TypeFlags.BooleanLike) { - targets.push(booleanType); - } - if (kind & TypeFlags.Void) { - targets.push(voidType); - } - if (kind & TypeFlags.Never) { - targets.push(neverType); - } - if (kind & TypeFlags.Null) { - targets.push(nullType); - } - if (kind & TypeFlags.Undefined) { - targets.push(undefinedType); - } - if (kind & TypeFlags.ESSymbol) { - targets.push(esSymbolType); - } - if (kind & TypeFlags.NonPrimitive) { - targets.push(nonPrimitiveType); - } - return isTypeAssignableTo(source, getUnionType(targets)); + return kind & TypeFlags.NumberLike && isTypeAssignableTo(source, numberType) || + kind & TypeFlags.StringLike && isTypeAssignableTo(source, stringType) || + kind & TypeFlags.BooleanLike && isTypeAssignableTo(source, booleanType) || + kind & TypeFlags.Void && isTypeAssignableTo(source, voidType) || + kind & TypeFlags.Never && isTypeAssignableTo(source, neverType) || + kind & TypeFlags.Null && isTypeAssignableTo(source, nullType) || + kind & TypeFlags.Undefined && isTypeAssignableTo(source, undefinedType) || + kind & TypeFlags.ESSymbol && isTypeAssignableTo(source, esSymbolType) || + kind & TypeFlags.NonPrimitive && isTypeAssignableTo(source, nonPrimitiveType); } function isConstEnumObjectType(type: Type): boolean { From aed386c796046153e76196af8ed4135cbeaebc8c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 2 Aug 2017 10:33:15 -0700 Subject: [PATCH 6/8] Add regression test cases and rename test --- .../reference/typeParamExtendsNumber.js | 19 ---- .../reference/typeParamExtendsNumber.symbols | 20 ----- .../reference/typeParamExtendsNumber.types | 23 ----- .../typeParameterExtendsPrimitive.js | 51 +++++++++++ .../typeParameterExtendsPrimitive.symbols | 82 +++++++++++++++++ .../typeParameterExtendsPrimitive.types | 90 +++++++++++++++++++ .../cases/compiler/typeParamExtendsNumber.ts | 7 -- .../compiler/typeParameterExtendsPrimitive.ts | 25 ++++++ 8 files changed, 248 insertions(+), 69 deletions(-) delete mode 100644 tests/baselines/reference/typeParamExtendsNumber.js delete mode 100644 tests/baselines/reference/typeParamExtendsNumber.symbols delete mode 100644 tests/baselines/reference/typeParamExtendsNumber.types create mode 100644 tests/baselines/reference/typeParameterExtendsPrimitive.js create mode 100644 tests/baselines/reference/typeParameterExtendsPrimitive.symbols create mode 100644 tests/baselines/reference/typeParameterExtendsPrimitive.types delete mode 100644 tests/cases/compiler/typeParamExtendsNumber.ts create mode 100644 tests/cases/compiler/typeParameterExtendsPrimitive.ts diff --git a/tests/baselines/reference/typeParamExtendsNumber.js b/tests/baselines/reference/typeParamExtendsNumber.js deleted file mode 100644 index 70548e7985610..0000000000000 --- a/tests/baselines/reference/typeParamExtendsNumber.js +++ /dev/null @@ -1,19 +0,0 @@ -//// [typeParamExtendsNumber.ts] -function f() { - var t: T; - var v = { - [t]: 0 - } - return t + t; -} - - -//// [typeParamExtendsNumber.js] -function f() { - var t; - var v = (_a = {}, - _a[t] = 0, - _a); - return t + t; - var _a; -} diff --git a/tests/baselines/reference/typeParamExtendsNumber.symbols b/tests/baselines/reference/typeParamExtendsNumber.symbols deleted file mode 100644 index 032f08bd58c26..0000000000000 --- a/tests/baselines/reference/typeParamExtendsNumber.symbols +++ /dev/null @@ -1,20 +0,0 @@ -=== tests/cases/compiler/typeParamExtendsNumber.ts === -function f() { ->f : Symbol(f, Decl(typeParamExtendsNumber.ts, 0, 0)) ->T : Symbol(T, Decl(typeParamExtendsNumber.ts, 0, 11)) - - var t: T; ->t : Symbol(t, Decl(typeParamExtendsNumber.ts, 1, 7)) ->T : Symbol(T, Decl(typeParamExtendsNumber.ts, 0, 11)) - - var v = { ->v : Symbol(v, Decl(typeParamExtendsNumber.ts, 2, 7)) - - [t]: 0 ->t : Symbol(t, Decl(typeParamExtendsNumber.ts, 1, 7)) - } - return t + t; ->t : Symbol(t, Decl(typeParamExtendsNumber.ts, 1, 7)) ->t : Symbol(t, Decl(typeParamExtendsNumber.ts, 1, 7)) -} - diff --git a/tests/baselines/reference/typeParamExtendsNumber.types b/tests/baselines/reference/typeParamExtendsNumber.types deleted file mode 100644 index 9034e23ee23d4..0000000000000 --- a/tests/baselines/reference/typeParamExtendsNumber.types +++ /dev/null @@ -1,23 +0,0 @@ -=== tests/cases/compiler/typeParamExtendsNumber.ts === -function f() { ->f : () => number ->T : T - - var t: T; ->t : T ->T : T - - var v = { ->v : { [x: number]: number; } ->{ [t]: 0 } : { [x: number]: number; } - - [t]: 0 ->t : T ->0 : 0 - } - return t + t; ->t + t : number ->t : T ->t : T -} - diff --git a/tests/baselines/reference/typeParameterExtendsPrimitive.js b/tests/baselines/reference/typeParameterExtendsPrimitive.js new file mode 100644 index 0000000000000..1774db19f6ead --- /dev/null +++ b/tests/baselines/reference/typeParameterExtendsPrimitive.js @@ -0,0 +1,51 @@ +//// [typeParameterExtendsPrimitive.ts] +// #14473 +function f() { + var t: T; + var v = { + [t]: 0 + } + return t + t; +} + +// #15501 +interface I { x: number } +type IdMap = { [P in keyof T]: T[P] }; +function g(i: IdMap) { + const n: number = i.x; + return i.x * 2; +} + +// #17069 +function h, K extends string>(array: T[], prop: K): number { + let result = 0; + for (const v of array) { + result += v[prop]; + } + return result; +} + + +//// [typeParameterExtendsPrimitive.js] +// #14473 +function f() { + var t; + var v = (_a = {}, + _a[t] = 0, + _a); + return t + t; + var _a; +} +function g(i) { + var n = i.x; + return i.x * 2; +} +// #17069 +function h(array, prop) { + var result = 0; + for (var _i = 0, array_1 = array; _i < array_1.length; _i++) { + var v = array_1[_i]; + result += v[prop]; + } + return result; +} diff --git a/tests/baselines/reference/typeParameterExtendsPrimitive.symbols b/tests/baselines/reference/typeParameterExtendsPrimitive.symbols new file mode 100644 index 0000000000000..acac75272ac84 --- /dev/null +++ b/tests/baselines/reference/typeParameterExtendsPrimitive.symbols @@ -0,0 +1,82 @@ +=== tests/cases/compiler/typeParameterExtendsPrimitive.ts === +// #14473 +function f() { +>f : Symbol(f, Decl(typeParameterExtendsPrimitive.ts, 0, 0)) +>T : Symbol(T, Decl(typeParameterExtendsPrimitive.ts, 1, 11)) + + var t: T; +>t : Symbol(t, Decl(typeParameterExtendsPrimitive.ts, 2, 7)) +>T : Symbol(T, Decl(typeParameterExtendsPrimitive.ts, 1, 11)) + + var v = { +>v : Symbol(v, Decl(typeParameterExtendsPrimitive.ts, 3, 7)) + + [t]: 0 +>t : Symbol(t, Decl(typeParameterExtendsPrimitive.ts, 2, 7)) + } + return t + t; +>t : Symbol(t, Decl(typeParameterExtendsPrimitive.ts, 2, 7)) +>t : Symbol(t, Decl(typeParameterExtendsPrimitive.ts, 2, 7)) +} + +// #15501 +interface I { x: number } +>I : Symbol(I, Decl(typeParameterExtendsPrimitive.ts, 7, 1)) +>x : Symbol(I.x, Decl(typeParameterExtendsPrimitive.ts, 10, 13)) + +type IdMap = { [P in keyof T]: T[P] }; +>IdMap : Symbol(IdMap, Decl(typeParameterExtendsPrimitive.ts, 10, 25)) +>T : Symbol(T, Decl(typeParameterExtendsPrimitive.ts, 11, 11)) +>P : Symbol(P, Decl(typeParameterExtendsPrimitive.ts, 11, 19)) +>T : Symbol(T, Decl(typeParameterExtendsPrimitive.ts, 11, 11)) +>T : Symbol(T, Decl(typeParameterExtendsPrimitive.ts, 11, 11)) +>P : Symbol(P, Decl(typeParameterExtendsPrimitive.ts, 11, 19)) + +function g(i: IdMap) { +>g : Symbol(g, Decl(typeParameterExtendsPrimitive.ts, 11, 41)) +>T : Symbol(T, Decl(typeParameterExtendsPrimitive.ts, 12, 11)) +>I : Symbol(I, Decl(typeParameterExtendsPrimitive.ts, 7, 1)) +>i : Symbol(i, Decl(typeParameterExtendsPrimitive.ts, 12, 24)) +>IdMap : Symbol(IdMap, Decl(typeParameterExtendsPrimitive.ts, 10, 25)) +>T : Symbol(T, Decl(typeParameterExtendsPrimitive.ts, 12, 11)) + + const n: number = i.x; +>n : Symbol(n, Decl(typeParameterExtendsPrimitive.ts, 13, 9)) +>i.x : Symbol(x, Decl(typeParameterExtendsPrimitive.ts, 10, 13)) +>i : Symbol(i, Decl(typeParameterExtendsPrimitive.ts, 12, 24)) +>x : Symbol(x, Decl(typeParameterExtendsPrimitive.ts, 10, 13)) + + return i.x * 2; +>i.x : Symbol(x, Decl(typeParameterExtendsPrimitive.ts, 10, 13)) +>i : Symbol(i, Decl(typeParameterExtendsPrimitive.ts, 12, 24)) +>x : Symbol(x, Decl(typeParameterExtendsPrimitive.ts, 10, 13)) +} + +// #17069 +function h, K extends string>(array: T[], prop: K): number { +>h : Symbol(h, Decl(typeParameterExtendsPrimitive.ts, 15, 1)) +>T : Symbol(T, Decl(typeParameterExtendsPrimitive.ts, 18, 11)) +>Record : Symbol(Record, Decl(lib.d.ts, --, --)) +>K : Symbol(K, Decl(typeParameterExtendsPrimitive.ts, 18, 39)) +>K : Symbol(K, Decl(typeParameterExtendsPrimitive.ts, 18, 39)) +>array : Symbol(array, Decl(typeParameterExtendsPrimitive.ts, 18, 58)) +>T : Symbol(T, Decl(typeParameterExtendsPrimitive.ts, 18, 11)) +>prop : Symbol(prop, Decl(typeParameterExtendsPrimitive.ts, 18, 69)) +>K : Symbol(K, Decl(typeParameterExtendsPrimitive.ts, 18, 39)) + + let result = 0; +>result : Symbol(result, Decl(typeParameterExtendsPrimitive.ts, 19, 7)) + + for (const v of array) { +>v : Symbol(v, Decl(typeParameterExtendsPrimitive.ts, 20, 14)) +>array : Symbol(array, Decl(typeParameterExtendsPrimitive.ts, 18, 58)) + + result += v[prop]; +>result : Symbol(result, Decl(typeParameterExtendsPrimitive.ts, 19, 7)) +>v : Symbol(v, Decl(typeParameterExtendsPrimitive.ts, 20, 14)) +>prop : Symbol(prop, Decl(typeParameterExtendsPrimitive.ts, 18, 69)) + } + return result; +>result : Symbol(result, Decl(typeParameterExtendsPrimitive.ts, 19, 7)) +} + diff --git a/tests/baselines/reference/typeParameterExtendsPrimitive.types b/tests/baselines/reference/typeParameterExtendsPrimitive.types new file mode 100644 index 0000000000000..1e8eb7f40e058 --- /dev/null +++ b/tests/baselines/reference/typeParameterExtendsPrimitive.types @@ -0,0 +1,90 @@ +=== tests/cases/compiler/typeParameterExtendsPrimitive.ts === +// #14473 +function f() { +>f : () => number +>T : T + + var t: T; +>t : T +>T : T + + var v = { +>v : { [x: number]: number; } +>{ [t]: 0 } : { [x: number]: number; } + + [t]: 0 +>t : T +>0 : 0 + } + return t + t; +>t + t : number +>t : T +>t : T +} + +// #15501 +interface I { x: number } +>I : I +>x : number + +type IdMap = { [P in keyof T]: T[P] }; +>IdMap : IdMap +>T : T +>P : P +>T : T +>T : T +>P : P + +function g(i: IdMap) { +>g : (i: IdMap) => number +>T : T +>I : I +>i : IdMap +>IdMap : IdMap +>T : T + + const n: number = i.x; +>n : number +>i.x : T["x"] +>i : IdMap +>x : T["x"] + + return i.x * 2; +>i.x * 2 : number +>i.x : T["x"] +>i : IdMap +>x : T["x"] +>2 : 2 +} + +// #17069 +function h, K extends string>(array: T[], prop: K): number { +>h : , K extends string>(array: T[], prop: K) => number +>T : T +>Record : Record +>K : K +>K : K +>array : T[] +>T : T +>prop : K +>K : K + + let result = 0; +>result : number +>0 : 0 + + for (const v of array) { +>v : T +>array : T[] + + result += v[prop]; +>result += v[prop] : number +>result : number +>v[prop] : T[K] +>v : T +>prop : K + } + return result; +>result : number +} + diff --git a/tests/cases/compiler/typeParamExtendsNumber.ts b/tests/cases/compiler/typeParamExtendsNumber.ts deleted file mode 100644 index 89b60c990a245..0000000000000 --- a/tests/cases/compiler/typeParamExtendsNumber.ts +++ /dev/null @@ -1,7 +0,0 @@ -function f() { - var t: T; - var v = { - [t]: 0 - } - return t + t; -} diff --git a/tests/cases/compiler/typeParameterExtendsPrimitive.ts b/tests/cases/compiler/typeParameterExtendsPrimitive.ts new file mode 100644 index 0000000000000..b94a44b46600b --- /dev/null +++ b/tests/cases/compiler/typeParameterExtendsPrimitive.ts @@ -0,0 +1,25 @@ +// #14473 +function f() { + var t: T; + var v = { + [t]: 0 + } + return t + t; +} + +// #15501 +interface I { x: number } +type IdMap = { [P in keyof T]: T[P] }; +function g(i: IdMap) { + const n: number = i.x; + return i.x * 2; +} + +// #17069 +function h, K extends string>(array: T[], prop: K): number { + let result = 0; + for (const v of array) { + result += v[prop]; + } + return result; +} From e47df360dc050bce8fa3f559c6506d1a8e739d7c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 8 Aug 2017 14:51:06 -0700 Subject: [PATCH 7/8] Use isTypeAny instead of checking flags directly --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0fc2b9275152f..ff1d157c4fa93 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -17148,7 +17148,7 @@ namespace ts { // and the right operand to be of type Any, a subtype of the 'Function' interface type, or have a call or construct signature. // The result is always of the Boolean primitive type. // NOTE: do not raise error if leftType is unknown as related error was already reported - if (!(leftType.flags & TypeFlags.Any) && isTypeAssignableToKind(leftType, TypeFlags.Primitive)) { + if (!isTypeAny(leftType) && isTypeAssignableToKind(leftType, TypeFlags.Primitive)) { error(left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported From fac93a304c816eea3b4f078ffe6f4567da145098 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 8 Aug 2017 16:11:42 -0700 Subject: [PATCH 8/8] Add parentheses:clarify evaluation order of &&/|| in isTypeAssignableToKind --- src/compiler/checker.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ff1d157c4fa93..33457daeccbca 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -17120,15 +17120,15 @@ namespace ts { if (strict && source.flags & (TypeFlags.Any | TypeFlags.Void | TypeFlags.Undefined | TypeFlags.Null)) { return false; } - return kind & TypeFlags.NumberLike && isTypeAssignableTo(source, numberType) || - kind & TypeFlags.StringLike && isTypeAssignableTo(source, stringType) || - kind & TypeFlags.BooleanLike && isTypeAssignableTo(source, booleanType) || - kind & TypeFlags.Void && isTypeAssignableTo(source, voidType) || - kind & TypeFlags.Never && isTypeAssignableTo(source, neverType) || - kind & TypeFlags.Null && isTypeAssignableTo(source, nullType) || - kind & TypeFlags.Undefined && isTypeAssignableTo(source, undefinedType) || - kind & TypeFlags.ESSymbol && isTypeAssignableTo(source, esSymbolType) || - kind & TypeFlags.NonPrimitive && isTypeAssignableTo(source, nonPrimitiveType); + return (kind & TypeFlags.NumberLike && isTypeAssignableTo(source, numberType)) || + (kind & TypeFlags.StringLike && isTypeAssignableTo(source, stringType)) || + (kind & TypeFlags.BooleanLike && isTypeAssignableTo(source, booleanType)) || + (kind & TypeFlags.Void && isTypeAssignableTo(source, voidType)) || + (kind & TypeFlags.Never && isTypeAssignableTo(source, neverType)) || + (kind & TypeFlags.Null && isTypeAssignableTo(source, nullType)) || + (kind & TypeFlags.Undefined && isTypeAssignableTo(source, undefinedType)) || + (kind & TypeFlags.ESSymbol && isTypeAssignableTo(source, esSymbolType)) || + (kind & TypeFlags.NonPrimitive && isTypeAssignableTo(source, nonPrimitiveType)); } function isConstEnumObjectType(type: Type): boolean {