Merge pull request #17404 from Microsoft/use-type-param-constraints-for-computed-prop-types

Use type parameter constraints for computed property types
This commit is contained in:
Nathan Shively-Sanders 2017-08-08 16:29:28 -07:00 committed by GitHub
commit 847d7fe3c8
31 changed files with 696 additions and 494 deletions

View File

@ -7556,11 +7556,11 @@ namespace ts {
return getTypeOfSymbol(prop);
}
}
if (isTypeAnyOrAllConstituentTypesHaveKind(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 = isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.NumberLike) && getIndexInfoOfType(objectType, IndexKind.Number) ||
const indexInfo = isTypeAssignableToKind(indexType, TypeFlags.NumberLike) && getIndexInfoOfType(objectType, IndexKind.Number) ||
getIndexInfoOfType(objectType, IndexKind.String) ||
undefined;
if (indexInfo) {
@ -11384,7 +11384,7 @@ namespace ts {
(<BinaryExpression>parent.parent).operatorToken.kind === SyntaxKind.EqualsToken &&
(<BinaryExpression>parent.parent).left === parent &&
!isAssignmentTarget(parent.parent) &&
isTypeAnyOrAllConstituentTypesHaveKind(getTypeOfExpression((<ElementAccessExpression>parent).argumentExpression), TypeFlags.NumberLike | TypeFlags.Undefined);
isTypeAssignableToKind(getTypeOfExpression((<ElementAccessExpression>parent).argumentExpression), TypeFlags.NumberLike);
return isLengthPushOrUnshift || isElementAssignment;
}
@ -11556,7 +11556,7 @@ namespace ts {
}
else {
const indexType = getTypeOfExpression((<ElementAccessExpression>(<BinaryExpression>node).left).argumentExpression);
if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.NumberLike | TypeFlags.Undefined)) {
if (isTypeAssignableToKind(indexType, TypeFlags.NumberLike)) {
evolvedType = addEvolvingArrayElementType(evolvedType, (<BinaryExpression>node).right);
}
}
@ -13398,11 +13398,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 isTypeAssignableToKind(checkComputedPropertyName(name), TypeFlags.NumberLike);
}
function isInfinityOrNaNString(name: string | __String): boolean {
@ -13438,10 +13434,11 @@ namespace ts {
const links = getNodeLinks(node.expression);
if (!links.resolvedType) {
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 (!isTypeAnyOrAllConstituentTypesHaveKind(links.resolvedType, TypeFlags.NumberLike | TypeFlags.StringLike | 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 {
@ -15546,7 +15543,7 @@ namespace ts {
case SyntaxKind.ComputedPropertyName:
const nameType = checkComputedPropertyName(element.name);
if (isTypeOfKind(nameType, TypeFlags.ESSymbol)) {
if (isTypeAssignableToKind(nameType, TypeFlags.ESSymbol)) {
return nameType;
}
else {
@ -16936,7 +16933,7 @@ namespace ts {
}
function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage): boolean {
if (!isTypeAnyOrAllConstituentTypesHaveKind(type, TypeFlags.NumberLike)) {
if (!isTypeAssignableToKind(type, TypeFlags.NumberLike)) {
error(operand, diagnostic);
return false;
}
@ -17114,31 +17111,22 @@ 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 isTypeAssignableToKind(source: Type, kind: TypeFlags, strict?: boolean): boolean {
if (source.flags & kind) {
return true;
}
if (type.flags & TypeFlags.Union) {
const types = (<UnionOrIntersectionType>type).types;
for (const t of types) {
if (!isTypeOfKind(t, kind)) {
return false;
}
}
return true;
if (strict && source.flags & (TypeFlags.Any | TypeFlags.Void | TypeFlags.Undefined | TypeFlags.Null)) {
return false;
}
if (type.flags & TypeFlags.Intersection) {
const types = (<UnionOrIntersectionType>type).types;
for (const t of types) {
if (isTypeOfKind(t, kind)) {
return true;
}
}
}
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));
}
function isConstEnumObjectType(type: Type): boolean {
@ -17158,7 +17146,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 (!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
@ -17181,10 +17169,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 (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.Object | TypeFlags.TypeVariable | TypeFlags.NonPrimitive)) {
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;
@ -17493,32 +17481,30 @@ namespace ts {
return silentNeverType;
}
if (!isTypeOfKind(leftType, TypeFlags.Any | TypeFlags.StringLike) && !isTypeOfKind(rightType, TypeFlags.Any | 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) && isTypeOfKind(rightType, TypeFlags.NumberLike)) {
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) || isTypeOfKind(rightType, TypeFlags.StringLike)) {
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.
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) {
@ -18732,7 +18718,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;
@ -20439,7 +20425,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 (!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);
}
@ -23426,22 +23412,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)) {

View File

@ -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'.
~~~~~~~~~~~~~~~~~~
!!! error TS2365: Operator '+' cannot be applied to types 'null' and '() => void'.

View File

@ -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;

View File

@ -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'.
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'.

View File

@ -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'.

View File

@ -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'.
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and '() => void'.

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<T, K extends keyof T>() {
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
};
}

View File

@ -0,0 +1,21 @@
//// [computedPropertyNames51_ES5.ts]
function f<T, K extends keyof T>() {
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;
}

View File

@ -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<T, K extends keyof T>() {
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
};
}

View File

@ -0,0 +1,20 @@
//// [computedPropertyNames51_ES6.ts]
function f<T, K extends keyof T>() {
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
};
}

View File

@ -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<T, U extends string>() {
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'.
};
}

View File

@ -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<T, U extends string>() {
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'.
};
}

View File

@ -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.

View File

@ -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;

View File

@ -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.

View File

@ -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;

View File

@ -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() {

View File

@ -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'.
~~~~~~~~~~~~~~~
!!! error TS2365: Operator '+' cannot be applied to types 'E' and 'undefined'.

View File

@ -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;

View File

@ -0,0 +1,51 @@
//// [typeParameterExtendsPrimitive.ts]
// #14473
function f<T extends number>() {
var t: T;
var v = {
[t]: 0
}
return t + t;
}
// #15501
interface I { x: number }
type IdMap<T> = { [P in keyof T]: T[P] };
function g<T extends I>(i: IdMap<T>) {
const n: number = i.x;
return i.x * 2;
}
// #17069
function h<T extends Record<K, number>, 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;
}

View File

@ -0,0 +1,82 @@
=== tests/cases/compiler/typeParameterExtendsPrimitive.ts ===
// #14473
function f<T extends number>() {
>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<T> = { [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<T extends I>(i: IdMap<T>) {
>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<T extends Record<K, number>, 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))
}

View File

@ -0,0 +1,90 @@
=== tests/cases/compiler/typeParameterExtendsPrimitive.ts ===
// #14473
function f<T extends number>() {
>f : <T extends number>() => 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<T> = { [P in keyof T]: T[P] };
>IdMap : IdMap<T>
>T : T
>P : P
>T : T
>T : T
>P : P
function g<T extends I>(i: IdMap<T>) {
>g : <T extends I>(i: IdMap<T>) => number
>T : T
>I : I
>i : IdMap<T>
>IdMap : IdMap<T>
>T : T
const n: number = i.x;
>n : number
>i.x : T["x"]
>i : IdMap<T>
>x : T["x"]
return i.x * 2;
>i.x * 2 : number
>i.x : T["x"]
>i : IdMap<T>
>x : T["x"]
>2 : 2
}
// #17069
function h<T extends Record<K, number>, K extends string>(array: T[], prop: K): number {
>h : <T extends Record<K, number>, K extends string>(array: T[], prop: K) => number
>T : T
>Record : Record<K, T>
>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
}

View File

@ -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;

View File

@ -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;

View File

@ -0,0 +1,25 @@
// #14473
function f<T extends number>() {
var t: T;
var v = {
[t]: 0
}
return t + t;
}
// #15501
interface I { x: number }
type IdMap<T> = { [P in keyof T]: T[P] };
function g<T extends I>(i: IdMap<T>) {
const n: number = i.x;
return i.x * 2;
}
// #17069
function h<T extends Record<K, number>, K extends string>(array: T[], prop: K): number {
let result = 0;
for (const v of array) {
result += v[prop];
}
return result;
}

View File

@ -0,0 +1,8 @@
function f<T, K extends keyof T>() {
var t: T;
var k: K;
var v = {
[t]: 0,
[k]: 1
};
}

View File

@ -0,0 +1,9 @@
// @target: es6
function f<T, K extends keyof T>() {
var t: T;
var k: K;
var v = {
[t]: 0,
[k]: 1
};
}