diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index b1ad3076d7717..c1011e575683b 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1209,9 +1209,9 @@ namespace ts { } else { forEachChild(node, bind); - if (operator === SyntaxKind.EqualsToken && !isAssignmentTarget(node)) { + if (isAssignmentOperator(operator) && !isAssignmentTarget(node)) { bindAssignmentTargetFlow(node.left); - if (node.left.kind === SyntaxKind.ElementAccessExpression) { + if (operator === SyntaxKind.EqualsToken && node.left.kind === SyntaxKind.ElementAccessExpression) { const elementAccess = node.left; if (isNarrowableOperand(elementAccess.expression)) { currentFlow = createFlowArrayMutation(currentFlow, node); @@ -3097,6 +3097,8 @@ namespace ts { case SyntaxKind.InterfaceDeclaration: case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.ThisType: + case SyntaxKind.TypeOperator: + case SyntaxKind.IndexedAccessType: case SyntaxKind.LiteralType: // Types and signatures are TypeScript syntax, and exclude all other facts. transformFlags = TransformFlags.AssertTypeScript; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 627bf3bb2e297..7d0dd5892764d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -136,6 +136,7 @@ namespace ts { const voidType = createIntrinsicType(TypeFlags.Void, "void"); const neverType = createIntrinsicType(TypeFlags.Never, "never"); const silentNeverType = createIntrinsicType(TypeFlags.Never, "never"); + const stringOrNumberType = getUnionType([stringType, numberType]); const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -2248,6 +2249,17 @@ namespace ts { else if (type.flags & TypeFlags.StringOrNumberLiteral) { writer.writeStringLiteral(literalTypeToString(type)); } + else if (type.flags & TypeFlags.Index) { + writer.writeKeyword("keyof"); + writeSpace(writer); + writeType((type).type, TypeFormatFlags.InElementType); + } + else if (type.flags & TypeFlags.IndexedAccess) { + writeType((type).objectType, TypeFormatFlags.InElementType); + writePunctuation(writer, SyntaxKind.OpenBracketToken); + writeType((type).indexType, TypeFormatFlags.None); + writePunctuation(writer, SyntaxKind.CloseBracketToken); + } else { // Should never get here // { ... } @@ -4491,22 +4503,13 @@ namespace ts { * type itself. Note that the apparent type of a union type is the union type itself. */ function getApparentType(type: Type): Type { - if (type.flags & TypeFlags.TypeParameter) { - type = getApparentTypeOfTypeParameter(type); - } - if (type.flags & TypeFlags.StringLike) { - type = globalStringType; - } - else if (type.flags & TypeFlags.NumberLike) { - type = globalNumberType; - } - else if (type.flags & TypeFlags.BooleanLike) { - type = globalBooleanType; - } - else if (type.flags & TypeFlags.ESSymbol) { - type = getGlobalESSymbolType(); - } - return type; + const t = type.flags & TypeFlags.TypeParameter ? getApparentTypeOfTypeParameter(type) : type; + return t.flags & TypeFlags.StringLike ? globalStringType : + t.flags & TypeFlags.NumberLike ? globalNumberType : + t.flags & TypeFlags.BooleanLike ? globalBooleanType : + t.flags & TypeFlags.ESSymbol ? getGlobalESSymbolType() : + t.flags & TypeFlags.Index ? stringOrNumberType : + t; } function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: string): Symbol { @@ -5692,6 +5695,145 @@ namespace ts { return links.resolvedType; } + function getIndexTypeForTypeParameter(type: TypeParameter) { + if (!type.resolvedIndexType) { + type.resolvedIndexType = createType(TypeFlags.Index); + type.resolvedIndexType.type = type; + } + return type.resolvedIndexType; + } + + function getLiteralTypeFromPropertyName(prop: Symbol) { + return startsWith(prop.name, "__@") ? neverType : getLiteralTypeForText(TypeFlags.StringLiteral, unescapeIdentifier(prop.name)); + } + + function getLiteralTypeFromPropertyNames(type: Type) { + return getUnionType(map(getPropertiesOfType(type), getLiteralTypeFromPropertyName)); + } + + function getIndexType(type: Type): Type { + return type.flags & TypeFlags.TypeParameter ? getIndexTypeForTypeParameter(type) : + type.flags & TypeFlags.Any || getIndexInfoOfType(type, IndexKind.String) ? stringOrNumberType : + getIndexInfoOfType(type, IndexKind.Number) ? getUnionType([numberType, getLiteralTypeFromPropertyNames(type)]) : + getLiteralTypeFromPropertyNames(type); + } + + function getTypeFromTypeOperatorNode(node: TypeOperatorNode) { + const links = getNodeLinks(node); + if (!links.resolvedType) { + links.resolvedType = getIndexType(getTypeFromTypeNodeNoAlias(node.type)); + } + return links.resolvedType; + } + + function createIndexedAccessType(objectType: Type, indexType: TypeParameter) { + const type = createType(TypeFlags.IndexedAccess); + type.objectType = objectType; + type.indexType = indexType; + return type; + } + + function getIndexedAccessTypeForTypeParameter(objectType: Type, indexType: TypeParameter) { + const indexedAccessTypes = indexType.resolvedIndexedAccessTypes || (indexType.resolvedIndexedAccessTypes = []); + return indexedAccessTypes[objectType.id] || (indexedAccessTypes[objectType.id] = createIndexedAccessType(objectType, indexType)); + } + + function getPropertyTypeForIndexType(objectType: Type, indexType: Type, accessNode: ElementAccessExpression | IndexedAccessTypeNode, cacheSymbol: boolean) { + const accessExpression = accessNode && accessNode.kind === SyntaxKind.ElementAccessExpression ? accessNode : undefined; + const propName = indexType.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral | TypeFlags.EnumLiteral) ? + (indexType).text : + accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ? + getPropertyNameForKnownSymbolName(((accessExpression.argumentExpression).name).text) : + undefined; + if (propName) { + const prop = getPropertyOfType(objectType, propName); + if (prop) { + if (accessExpression) { + if (isAssignmentTarget(accessExpression) && (isReferenceToReadonlyEntity(accessExpression, prop) || isReferenceThroughNamespaceImport(accessExpression))) { + error(accessExpression.argumentExpression, Diagnostics.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, symbolToString(prop)); + return unknownType; + } + if (cacheSymbol) { + getNodeLinks(accessNode).resolvedSymbol = prop; + } + } + return getTypeOfSymbol(prop); + } + } + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { + if (isTypeAny(objectType)) { + return anyType; + } + const indexInfo = isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.NumberLike) && getIndexInfoOfType(objectType, IndexKind.Number) || + getIndexInfoOfType(objectType, IndexKind.String) || + undefined; + if (indexInfo) { + if (accessExpression && isAssignmentTarget(accessExpression) && indexInfo.isReadonly) { + error(accessExpression, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(objectType)); + return unknownType; + } + return indexInfo.type; + } + if (accessExpression && !isConstEnumObjectType(objectType)) { + if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors) { + if (getIndexTypeOfType(objectType, IndexKind.Number)) { + error(accessExpression.argumentExpression, Diagnostics.Element_implicitly_has_an_any_type_because_index_expression_is_not_of_type_number); + } + else { + error(accessExpression, Diagnostics.Element_implicitly_has_an_any_type_because_type_0_has_no_index_signature, typeToString(objectType)); + } + } + return anyType; + } + } + if (accessNode) { + const indexNode = accessNode.kind === SyntaxKind.ElementAccessExpression ? (accessNode).argumentExpression : (accessNode).indexType; + if (indexType.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral)) { + error(indexNode, Diagnostics.Property_0_does_not_exist_on_type_1, (indexType).text, typeToString(objectType)); + } + else if (indexType.flags & (TypeFlags.String | TypeFlags.Number)) { + error(indexNode, Diagnostics.Type_0_has_no_matching_index_signature_for_type_1, typeToString(objectType), typeToString(indexType)); + } + else { + error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType)); + } + } + return unknownType; + } + + function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode) { + if (indexType.flags & TypeFlags.TypeParameter) { + if (!isTypeAssignableTo(getConstraintOfTypeParameter(indexType) || emptyObjectType, getIndexType(objectType))) { + if (accessNode) { + error(accessNode, Diagnostics.Type_0_is_not_constrained_to_keyof_1, typeToString(indexType), typeToString(objectType)); + } + return unknownType; + } + return getIndexedAccessTypeForTypeParameter(objectType, indexType); + } + const apparentType = getApparentType(objectType); + if (indexType.flags & TypeFlags.Union && !(indexType.flags & TypeFlags.Primitive)) { + const propTypes: Type[] = []; + for (const t of (indexType).types) { + const propType = getPropertyTypeForIndexType(apparentType, t, accessNode, /*cacheSymbol*/ false); + if (propType === unknownType) { + return unknownType; + } + propTypes.push(propType); + } + return getUnionType(propTypes); + } + return getPropertyTypeForIndexType(apparentType, indexType, accessNode, /*cacheSymbol*/ true); + } + + function getTypeFromIndexedAccessTypeNode(node: IndexedAccessTypeNode) { + const links = getNodeLinks(node); + if (!links.resolvedType) { + links.resolvedType = getIndexedAccessType(getTypeFromTypeNodeNoAlias(node.objectType), getTypeFromTypeNodeNoAlias(node.indexType), node); + } + return links.resolvedType; + } + function getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node: Node, aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type { const links = getNodeLinks(node); if (!links.resolvedType) { @@ -5856,6 +5998,10 @@ namespace ts { case SyntaxKind.JSDocTypeLiteral: case SyntaxKind.JSDocFunctionType: return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node, aliasSymbol, aliasTypeArguments); + case SyntaxKind.TypeOperator: + return getTypeFromTypeOperatorNode(node); + case SyntaxKind.IndexedAccessType: + return getTypeFromIndexedAccessTypeNode(node); // This function assumes that an identifier or qualified name is a type expression // Callers should first ensure this by calling isTypeNode case SyntaxKind.Identifier: @@ -6120,6 +6266,12 @@ namespace ts { if (type.flags & TypeFlags.Intersection) { return getIntersectionType(instantiateList((type).types, mapper, instantiateType), type.aliasSymbol, mapper.targetTypes); } + if (type.flags & TypeFlags.Index) { + return getIndexType(instantiateType((type).type, mapper)); + } + if (type.flags & TypeFlags.IndexedAccess) { + return getIndexedAccessType(instantiateType((type).objectType, mapper), instantiateType((type).indexType, mapper)); + } } return type; } @@ -8055,7 +8207,7 @@ namespace ts { function hasPrimitiveConstraint(type: TypeParameter): boolean { const constraint = getConstraintOfTypeParameter(type); - return constraint && maybeTypeOfKind(constraint, TypeFlags.Primitive); + return constraint && maybeTypeOfKind(constraint, TypeFlags.Primitive | TypeFlags.Index); } function getInferredType(context: InferenceContext, index: number): Type { @@ -8766,7 +8918,7 @@ namespace ts { // Assignments only narrow the computed type if the declared type is a union type. Thus, we // only need to evaluate the assigned type if the declared type is a union type. if (isMatchingReference(reference, node)) { - if (node.parent.kind === SyntaxKind.PrefixUnaryExpression || node.parent.kind === SyntaxKind.PostfixUnaryExpression) { + if (getAssignmentTargetKind(node) === AssignmentKind.Compound) { const flowType = getTypeAtFlowNode(flow.antecedent); return createFlowType(getBaseTypeOfLiteralType(getTypeFromFlowType(flowType)), isIncomplete(flowType)); } @@ -9213,10 +9365,10 @@ namespace ts { } } else { - const invokedExpression = skipParenthesizedNodes(callExpression.expression); + const invokedExpression = skipParentheses(callExpression.expression); if (invokedExpression.kind === SyntaxKind.ElementAccessExpression || invokedExpression.kind === SyntaxKind.PropertyAccessExpression) { const accessExpression = invokedExpression as ElementAccessExpression | PropertyAccessExpression; - const possibleReference = skipParenthesizedNodes(accessExpression.expression); + const possibleReference = skipParentheses(accessExpression.expression); if (isMatchingReference(reference, possibleReference)) { return getNarrowedType(type, predicate.type, assumeTrue); } @@ -9276,13 +9428,6 @@ namespace ts { return getTypeOfSymbol(symbol); } - function skipParenthesizedNodes(expression: Expression): Expression { - while (expression.kind === SyntaxKind.ParenthesizedExpression) { - expression = (expression as ParenthesizedExpression).expression; - } - return expression; - } - function getControlFlowContainer(node: Node): Node { while (true) { node = node.parent; @@ -9340,6 +9485,9 @@ namespace ts { function checkIdentifier(node: Identifier): Type { const symbol = getResolvedSymbol(node); + if (symbol === unknownSymbol) { + return unknownType; + } // As noted in ECMAScript 6 language spec, arrow functions never have an arguments objects. // Although in down-level emit of arrow function, we emit it using function expression which means that @@ -9361,6 +9509,7 @@ namespace ts { if (node.flags & NodeFlags.AwaitContext) { getNodeLinks(container).flags |= NodeCheckFlags.CaptureArguments; } + return getTypeOfSymbol(symbol); } if (symbol.flags & SymbolFlags.Alias && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) { @@ -9413,9 +9562,22 @@ namespace ts { const type = getTypeOfSymbol(localOrExportSymbol); const declaration = localOrExportSymbol.valueDeclaration; + const assignmentKind = getAssignmentTargetKind(node); + + if (assignmentKind) { + if (!(localOrExportSymbol.flags & SymbolFlags.Variable)) { + error(node, Diagnostics.Cannot_assign_to_0_because_it_is_not_a_variable, symbolToString(symbol)); + return unknownType; + } + if (isReadonlySymbol(localOrExportSymbol)) { + error(node, Diagnostics.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, symbolToString(symbol)); + return unknownType; + } + } + // We only narrow variables and parameters occurring in a non-assignment position. For all other // entities we simply return the declared type. - if (!(localOrExportSymbol.flags & SymbolFlags.Variable) || isAssignmentTarget(node) || !declaration) { + if (!(localOrExportSymbol.flags & SymbolFlags.Variable) || assignmentKind === AssignmentKind.Definite || !declaration) { return type; } // The declaration container is the innermost function that encloses the declaration of the variable @@ -9457,7 +9619,7 @@ namespace ts { // Return the declared type to reduce follow-on errors return type; } - return flowType; + return assignmentKind ? getBaseTypeOfLiteralType(flowType) : flowType; } function isInsideFunction(node: Node, threshold: Node): boolean { @@ -11328,6 +11490,20 @@ namespace ts { return checkPropertyAccessExpressionOrQualifiedName(node, node.left, node.right); } + function reportNonexistentProperty(propNode: Identifier, containingType: Type) { + let errorInfo: DiagnosticMessageChain; + if (containingType.flags & TypeFlags.Union && !(containingType.flags & TypeFlags.Primitive)) { + for (const subtype of (containingType as UnionType).types) { + if (!getPropertyOfType(subtype, propNode.text)) { + errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(subtype)); + break; + } + } + } + errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType)); + diagnostics.add(createDiagnosticForNodeFromMessageChain(propNode, errorInfo)); + } + function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) { const type = checkNonNullExpression(left); if (isTypeAny(type) || type === silentNeverType) { @@ -11366,30 +11542,25 @@ namespace ts { } const propType = getTypeOfSymbol(prop); + const assignmentKind = getAssignmentTargetKind(node); + + if (assignmentKind) { + if (isReferenceToReadonlyEntity(node, prop) || isReferenceThroughNamespaceImport(node)) { + error(right, Diagnostics.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, right.text); + return unknownType; + } + } // Only compute control flow type if this is a property access expression that isn't an // assignment target, and the referenced property was declared as a variable, property, // accessor, or optional method. - if (node.kind !== SyntaxKind.PropertyAccessExpression || isAssignmentTarget(node) || + if (node.kind !== SyntaxKind.PropertyAccessExpression || assignmentKind === AssignmentKind.Definite || !(prop.flags & (SymbolFlags.Variable | SymbolFlags.Property | SymbolFlags.Accessor)) && !(prop.flags & SymbolFlags.Method && propType.flags & TypeFlags.Union)) { return propType; } - return getFlowTypeOfReference(node, propType, /*assumeInitialized*/ true, /*flowContainer*/ undefined); - - function reportNonexistentProperty(propNode: Identifier, containingType: Type) { - let errorInfo: DiagnosticMessageChain; - if (containingType.flags & TypeFlags.Union && !(containingType.flags & TypeFlags.Primitive)) { - for (const subtype of (containingType as UnionType).types) { - if (!getPropertyOfType(subtype, propNode.text)) { - errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(subtype)); - break; - } - } - } - errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType)); - diagnostics.add(createDiagnosticForNodeFromMessageChain(propNode, errorInfo)); - } + const flowType = getFlowTypeOfReference(node, propType, /*assumeInitialized*/ true, /*flowContainer*/ undefined); + return assignmentKind ? getBaseTypeOfLiteralType(flowType) : flowType; } function isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean { @@ -11436,7 +11607,7 @@ namespace ts { * that references a for-in variable for an object with numeric property names. */ function isForInVariableForNumericPropertyNames(expr: Expression) { - const e = skipParenthesizedNodes(expr); + const e = skipParentheses(expr); if (e.kind === SyntaxKind.Identifier) { const symbol = getResolvedSymbol(e); if (symbol.flags & SymbolFlags.Variable) { @@ -11458,8 +11629,10 @@ namespace ts { } function checkIndexedAccess(node: ElementAccessExpression): Type { - // Grammar checking - if (!node.argumentExpression) { + const objectType = checkNonNullExpression(node.expression); + + const indexExpression = node.argumentExpression; + if (!indexExpression) { const sourceFile = getSourceFileOfNode(node); if (node.parent.kind === SyntaxKind.NewExpression && (node.parent).expression === node) { const start = skipTrivia(sourceFile.text, node.expression.end); @@ -11471,116 +11644,23 @@ namespace ts { const end = node.end; grammarErrorAtPos(sourceFile, start, end - start, Diagnostics.Expression_expected); } + return unknownType; } - // Obtain base constraint such that we can bail out if the constraint is an unknown type - const objectType = getApparentType(checkNonNullExpression(node.expression)); - const indexType = node.argumentExpression ? checkExpression(node.argumentExpression) : unknownType; + const indexType = isForInVariableForNumericPropertyNames(indexExpression) ? numberType : checkExpression(indexExpression); if (objectType === unknownType || objectType === silentNeverType) { return objectType; } - const isConstEnum = isConstEnumObjectType(objectType); - if (isConstEnum && - (!node.argumentExpression || node.argumentExpression.kind !== SyntaxKind.StringLiteral)) { - error(node.argumentExpression, Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal); + if (isConstEnumObjectType(objectType) && indexExpression.kind !== SyntaxKind.StringLiteral) { + error(indexExpression, Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal); return unknownType; } - // TypeScript 1.0 spec (April 2014): 4.10 Property Access - // - If IndexExpr is a string literal or a numeric literal and ObjExpr's apparent type has a property with the name - // given by that literal(converted to its string representation in the case of a numeric literal), the property access is of the type of that property. - // - Otherwise, if ObjExpr's apparent type has a numeric index signature and IndexExpr is of type Any, the Number primitive type, or an enum type, - // the property access is of the type of that index signature. - // - Otherwise, if ObjExpr's apparent type has a string index signature and IndexExpr is of type Any, the String or Number primitive type, or an enum type, - // the property access is of the type of that index signature. - // - Otherwise, if IndexExpr is of type Any, the String or Number primitive type, or an enum type, the property access is of type Any. - - // See if we can index as a property. - if (node.argumentExpression) { - const name = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); - if (name !== undefined) { - const prop = getPropertyOfType(objectType, name); - if (prop) { - getNodeLinks(node).resolvedSymbol = prop; - return getTypeOfSymbol(prop); - } - else if (isConstEnum) { - error(node.argumentExpression, Diagnostics.Property_0_does_not_exist_on_const_enum_1, name, symbolToString(objectType.symbol)); - return unknownType; - } - } - } - - // Check for compatible indexer types. - const allowedNullableFlags = strictNullChecks ? 0 : TypeFlags.Nullable; - if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol | allowedNullableFlags)) { - - // Try to use a number indexer. - if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.NumberLike | allowedNullableFlags) || isForInVariableForNumericPropertyNames(node.argumentExpression)) { - const numberIndexInfo = getIndexInfoOfType(objectType, IndexKind.Number); - if (numberIndexInfo) { - getNodeLinks(node).resolvedIndexInfo = numberIndexInfo; - return numberIndexInfo.type; - } - } - - // Try to use string indexing. - const stringIndexInfo = getIndexInfoOfType(objectType, IndexKind.String); - if (stringIndexInfo) { - getNodeLinks(node).resolvedIndexInfo = stringIndexInfo; - return stringIndexInfo.type; - } - - // Fall back to any. - if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTypeAny(objectType)) { - error(node, getIndexTypeOfType(objectType, IndexKind.Number) ? - Diagnostics.Element_implicitly_has_an_any_type_because_index_expression_is_not_of_type_number : - Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); - } - - return anyType; - } - - // REVIEW: Users should know the type that was actually used. - error(node, Diagnostics.An_index_expression_argument_must_be_of_type_string_number_symbol_or_any); - - return unknownType; + return getIndexedAccessType(objectType, indexType, node); } - /** - * If indexArgumentExpression is a string literal or number literal, returns its text. - * If indexArgumentExpression is a constant value, returns its string value. - * If indexArgumentExpression is a well known symbol, returns the property name corresponding - * to this symbol, as long as it is a proper symbol reference. - * Otherwise, returns undefined. - */ - function getPropertyNameForIndexedAccess(indexArgumentExpression: Expression, indexArgumentType: Type): string { - if (indexArgumentExpression.kind === SyntaxKind.StringLiteral || indexArgumentExpression.kind === SyntaxKind.NumericLiteral) { - return (indexArgumentExpression).text; - } - if (indexArgumentExpression.kind === SyntaxKind.ElementAccessExpression || indexArgumentExpression.kind === SyntaxKind.PropertyAccessExpression) { - const value = getConstantValue(indexArgumentExpression); - if (value !== undefined) { - return value.toString(); - } - } - if (checkThatExpressionIsProperSymbolReference(indexArgumentExpression, indexArgumentType, /*reportError*/ false)) { - const rightHandSideName = ((indexArgumentExpression).name).text; - return getPropertyNameForKnownSymbolName(rightHandSideName); - } - - return undefined; - } - - /** - * A proper symbol reference requires the following: - * 1. The property access denotes a property that exists - * 2. The expression is of the form Symbol. - * 3. The property access is of the primitive type symbol. - * 4. Symbol in this context resolves to the global Symbol object - */ function checkThatExpressionIsProperSymbolReference(expression: Expression, expressionType: Type, reportError: boolean): boolean { if (expressionType === unknownType) { // There is already an error, so no need to report one. @@ -13437,7 +13517,7 @@ namespace ts { function isReferenceThroughNamespaceImport(expr: Expression): boolean { if (expr.kind === SyntaxKind.PropertyAccessExpression || expr.kind === SyntaxKind.ElementAccessExpression) { - const node = skipParenthesizedNodes((expr as PropertyAccessExpression | ElementAccessExpression).expression); + const node = skipParentheses((expr as PropertyAccessExpression | ElementAccessExpression).expression); if (node.kind === SyntaxKind.Identifier) { const symbol = getNodeLinks(node).resolvedSymbol; if (symbol.flags & SymbolFlags.Alias) { @@ -13449,38 +13529,13 @@ namespace ts { return false; } - function checkReferenceExpression(expr: Expression, invalidReferenceMessage: DiagnosticMessage, constantVariableMessage: DiagnosticMessage): boolean { + function checkReferenceExpression(expr: Expression, invalidReferenceMessage: DiagnosticMessage): boolean { // References are combinations of identifiers, parentheses, and property accesses. - const node = skipParenthesizedNodes(expr); + const node = skipParentheses(expr); if (node.kind !== SyntaxKind.Identifier && node.kind !== SyntaxKind.PropertyAccessExpression && node.kind !== SyntaxKind.ElementAccessExpression) { error(expr, invalidReferenceMessage); return false; } - // Because we get the symbol from the resolvedSymbol property, it might be of kind - // SymbolFlags.ExportValue. In this case it is necessary to get the actual export - // symbol, which will have the correct flags set on it. - const links = getNodeLinks(node); - const symbol = getExportSymbolOfValueSymbolIfExported(links.resolvedSymbol); - if (symbol) { - if (symbol !== unknownSymbol && symbol !== argumentsSymbol) { - // Only variables (and not functions, classes, namespaces, enum objects, or enum members) - // are considered references when referenced using a simple identifier. - if (node.kind === SyntaxKind.Identifier && !(symbol.flags & SymbolFlags.Variable)) { - error(expr, invalidReferenceMessage); - return false; - } - if (isReferenceToReadonlyEntity(node, symbol) || isReferenceThroughNamespaceImport(node)) { - error(expr, constantVariableMessage); - return false; - } - } - } - else if (node.kind === SyntaxKind.ElementAccessExpression) { - if (links.resolvedIndexInfo && links.resolvedIndexInfo.isReadonly) { - error(expr, constantVariableMessage); - return false; - } - } return true; } @@ -13542,9 +13597,7 @@ namespace ts { Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { // run check only if former checks succeeded to avoid reporting cascading errors - checkReferenceExpression(node.operand, - Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, - Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant_or_a_read_only_property); + checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access); } return numberType; } @@ -13560,9 +13613,7 @@ namespace ts { Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { // run check only if former checks succeeded to avoid reporting cascading errors - checkReferenceExpression(node.operand, - Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, - Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant_or_a_read_only_property); + checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access); } return numberType; } @@ -13788,7 +13839,7 @@ namespace ts { function checkReferenceAssignment(target: Expression, sourceType: Type, contextualMapper?: TypeMapper): Type { const targetType = checkExpression(target, contextualMapper); - if (checkReferenceExpression(target, Diagnostics.Invalid_left_hand_side_of_assignment_expression, Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant_or_a_read_only_property)) { + if (checkReferenceExpression(target, Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access)) { checkTypeAssignableTo(sourceType, targetType, target, /*headMessage*/ undefined); } return sourceType; @@ -14071,11 +14122,7 @@ namespace ts { // requires VarExpr to be classified as a reference // A compound assignment furthermore requires VarExpr to be classified as a reference (section 4.1) // and the type of the non - compound operation to be assignable to the type of VarExpr. - const ok = checkReferenceExpression(left, - Diagnostics.Invalid_left_hand_side_of_assignment_expression, - Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant_or_a_read_only_property); - // Use default messages - if (ok) { + if (checkReferenceExpression(left, Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access)) { // to avoid cascading errors check assignability only if 'isReference' check succeeded and no errors were reported checkTypeAssignableTo(valueType, leftType, left, /*headMessage*/ undefined); } @@ -14206,7 +14253,7 @@ namespace ts { } function isTypeAssertion(node: Expression) { - node = skipParenthesizedNodes(node); + node = skipParentheses(node); return node.kind === SyntaxKind.TypeAssertionExpression || node.kind === SyntaxKind.AsExpression; } @@ -15021,6 +15068,10 @@ namespace ts { forEach(node.types, checkSourceElement); } + function checkIndexedAccessType(node: IndexedAccessTypeNode) { + getTypeFromIndexedAccessTypeNode(node); + } + function isPrivateWithinAmbient(node: Node): boolean { return (getModifierFlags(node) & ModifierFlags.Private) && isInAmbientContext(node); } @@ -16500,8 +16551,7 @@ namespace ts { } else { const leftType = checkExpression(varExpr); - checkReferenceExpression(varExpr, /*invalidReferenceMessage*/ Diagnostics.Invalid_left_hand_side_in_for_of_statement, - /*constantVariableMessage*/ Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_be_a_constant_or_a_read_only_property); + checkReferenceExpression(varExpr, Diagnostics.The_left_hand_side_of_a_for_of_statement_must_be_a_variable_or_a_property_access); // iteratedType will be undefined if the rightType was missing properties/signatures // required to get its iteratedType (like [Symbol.iterator] or next). This may be @@ -16551,8 +16601,7 @@ namespace ts { } else { // run check only former check succeeded to avoid cascading errors - checkReferenceExpression(varExpr, Diagnostics.Invalid_left_hand_side_in_for_in_statement, - Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_constant_or_a_read_only_property); + checkReferenceExpression(varExpr, Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_a_variable_or_a_property_access); } } @@ -18288,7 +18337,10 @@ namespace ts { case SyntaxKind.IntersectionType: return checkUnionOrIntersectionType(node); case SyntaxKind.ParenthesizedType: - return checkSourceElement((node).type); + case SyntaxKind.TypeOperator: + return checkSourceElement((node).type); + case SyntaxKind.IndexedAccessType: + return checkIndexedAccessType(node); case SyntaxKind.FunctionDeclaration: return checkFunctionDeclaration(node); case SyntaxKind.Block: diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 6458183b23c90..0bba375a2cb2e 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -413,6 +413,10 @@ namespace ts { return emitIntersectionType(type); case SyntaxKind.ParenthesizedType: return emitParenType(type); + case SyntaxKind.TypeOperator: + return emitTypeOperator(type); + case SyntaxKind.IndexedAccessType: + return emitPropertyAccessType(type); case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: return emitSignatureDeclarationWithJsDocComments(type); @@ -506,6 +510,19 @@ namespace ts { write(")"); } + function emitTypeOperator(type: TypeOperatorNode) { + write(tokenToString(type.operator)); + write(" "); + emitType(type.type); + } + + function emitPropertyAccessType(node: IndexedAccessTypeNode) { + emitType(node.objectType); + write("["); + emitType(node.indexType); + write("]"); + } + function emitTypeLiteral(type: TypeLiteralNode) { write("{"); if (type.members.length) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7d5a141884371..98c8e3693a27a 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1071,7 +1071,7 @@ "category": "Error", "code": 2356 }, - "The operand of an increment or decrement operator must be a variable, property or indexer.": { + "The operand of an increment or decrement operator must be a variable or a property access.": { "category": "Error", "code": 2357 }, @@ -1099,7 +1099,7 @@ "category": "Error", "code": 2363 }, - "Invalid left-hand side of assignment expression.": { + "The left-hand side of an assignment expression must be a variable or a property access.": { "category": "Error", "code": 2364 }, @@ -1259,7 +1259,7 @@ "category": "Error", "code": 2405 }, - "Invalid left-hand side in 'for...in' statement.": { + "The left-hand side of a 'for...in' statement must be a variable or a property access.": { "category": "Error", "code": 2406 }, @@ -1411,14 +1411,6 @@ "category": "Error", "code": 2448 }, - "The operand of an increment or decrement operator cannot be a constant or a read-only property.": { - "category": "Error", - "code": 2449 - }, - "Left-hand side of assignment expression cannot be a constant or a read-only property.": { - "category": "Error", - "code": 2450 - }, "Cannot redeclare block-scoped variable '{0}'.": { "category": "Error", "code": 2451 @@ -1551,15 +1543,7 @@ "category": "Error", "code": 2484 }, - "The left-hand side of a 'for...of' statement cannot be a constant or a read-only property.": { - "category": "Error", - "code": 2485 - }, - "The left-hand side of a 'for...in' statement cannot be a constant or a read-only property.": { - "category": "Error", - "code": 2486 - }, - "Invalid left-hand side in 'for...of' statement.": { + "The left-hand side of a 'for...of' statement must be a variable or a property access.": { "category": "Error", "code": 2487 }, @@ -1747,6 +1731,34 @@ "category": "Error", "code": 2535 }, + "Type '{0}' is not constrained to 'keyof {1}'.": { + "category": "Error", + "code": 2536 + }, + "Type '{0}' has no matching index signature for type '{1}'.": { + "category": "Error", + "code": 2537 + }, + "Type '{0}' cannot be used as an index type.": { + "category": "Error", + "code": 2538 + }, + "Cannot assign to '{0}' because it is not a variable.": { + "category": "Error", + "code": 2539 + }, + "Cannot assign to '{0}' because it is a constant or a read-only property.": { + "category": "Error", + "code": 2540 + }, + "The target of an assignment must be a variable or a property access.": { + "category": "Error", + "code": 2541 + }, + "Index signature in type '{0}' only permits reading.": { + "category": "Error", + "code": 2542 + }, "JSX element attributes type '{0}' may not be a union type.": { "category": "Error", "code": 2600 @@ -2909,7 +2921,7 @@ "category": "Error", "code": 7016 }, - "Index signature of object type implicitly has an 'any' type.": { + "Element implicitly has an 'any' type because type '{0}' has no index signature.": { "category": "Error", "code": 7017 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1051c9adca961..f29ef0f4cf1e2 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -594,6 +594,10 @@ const _super = (function (geti, seti) { return emitExpressionWithTypeArguments(node); case SyntaxKind.ThisType: return emitThisType(); + case SyntaxKind.TypeOperator: + return emitTypeOperator(node); + case SyntaxKind.IndexedAccessType: + return emitPropertyAccessType(node); case SyntaxKind.LiteralType: return emitLiteralType(node); @@ -1088,6 +1092,19 @@ const _super = (function (geti, seti) { write("this"); } + function emitTypeOperator(node: TypeOperatorNode) { + writeTokenText(node.operator); + write(" "); + emit(node.type); + } + + function emitPropertyAccessType(node: IndexedAccessTypeNode) { + emit(node.objectType); + write("["); + emit(node.indexType); + write("]"); + } + function emitLiteralType(node: LiteralTypeNode) { emitExpression(node.literal); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a5b02f98fd382..92a3dcbef11c7 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -134,7 +134,11 @@ namespace ts { case SyntaxKind.IntersectionType: return visitNodes(cbNodes, (node).types); case SyntaxKind.ParenthesizedType: - return visitNode(cbNode, (node).type); + case SyntaxKind.TypeOperator: + return visitNode(cbNode, (node).type); + case SyntaxKind.IndexedAccessType: + return visitNode(cbNode, (node).objectType) || + visitNode(cbNode, (node).indexType); case SyntaxKind.LiteralType: return visitNode(cbNode, (node).literal); case SyntaxKind.ObjectBindingPattern: @@ -2519,14 +2523,39 @@ namespace ts { function parseArrayTypeOrHigher(): TypeNode { let type = parseNonArrayType(); while (!scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) { - parseExpected(SyntaxKind.CloseBracketToken); - const node = createNode(SyntaxKind.ArrayType, type.pos); - node.elementType = type; - type = finishNode(node); + if (isStartOfType()) { + const node = createNode(SyntaxKind.IndexedAccessType, type.pos); + node.objectType = type; + node.indexType = parseType(); + parseExpected(SyntaxKind.CloseBracketToken); + type = finishNode(node); + } + else { + const node = createNode(SyntaxKind.ArrayType, type.pos); + node.elementType = type; + parseExpected(SyntaxKind.CloseBracketToken); + type = finishNode(node); + } } return type; } + function parseTypeOperator(operator: SyntaxKind.KeyOfKeyword) { + const node = createNode(SyntaxKind.TypeOperator); + parseExpected(operator); + node.operator = operator; + node.type = parseTypeOperatorOrHigher(); + return finishNode(node); + } + + function parseTypeOperatorOrHigher(): TypeNode { + switch (token()) { + case SyntaxKind.KeyOfKeyword: + return parseTypeOperator(SyntaxKind.KeyOfKeyword); + } + return parseArrayTypeOrHigher(); + } + function parseUnionOrIntersectionType(kind: SyntaxKind, parseConstituentType: () => TypeNode, operator: SyntaxKind): TypeNode { let type = parseConstituentType(); if (token() === operator) { @@ -2543,7 +2572,7 @@ namespace ts { } function parseIntersectionTypeOrHigher(): TypeNode { - return parseUnionOrIntersectionType(SyntaxKind.IntersectionType, parseArrayTypeOrHigher, SyntaxKind.AmpersandToken); + return parseUnionOrIntersectionType(SyntaxKind.IntersectionType, parseTypeOperatorOrHigher, SyntaxKind.AmpersandToken); } function parseUnionTypeOrHigher(): TypeNode { diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 1c0baa457f4af..82302e98e37a8 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -90,6 +90,7 @@ namespace ts { "instanceof": SyntaxKind.InstanceOfKeyword, "interface": SyntaxKind.InterfaceKeyword, "is": SyntaxKind.IsKeyword, + "keyof": SyntaxKind.KeyOfKeyword, "let": SyntaxKind.LetKeyword, "module": SyntaxKind.ModuleKeyword, "namespace": SyntaxKind.NamespaceKeyword, diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index fe264876b2581..1362746ba57a8 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -300,6 +300,8 @@ namespace ts { case SyntaxKind.IntersectionType: case SyntaxKind.ParenthesizedType: case SyntaxKind.ThisType: + case SyntaxKind.TypeOperator: + case SyntaxKind.IndexedAccessType: case SyntaxKind.LiteralType: // TypeScript type nodes are elided. @@ -1783,6 +1785,8 @@ namespace ts { } // Fallthrough case SyntaxKind.TypeQuery: + case SyntaxKind.TypeOperator: + case SyntaxKind.IndexedAccessType: case SyntaxKind.TypeLiteral: case SyntaxKind.AnyKeyword: case SyntaxKind.ThisType: diff --git a/src/compiler/types.ts b/src/compiler/types.ts index cefa3714017e6..381289b133b49 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -168,6 +168,7 @@ namespace ts { DeclareKeyword, GetKeyword, IsKeyword, + KeyOfKeyword, ModuleKeyword, NamespaceKeyword, NeverKeyword, @@ -216,6 +217,8 @@ namespace ts { IntersectionType, ParenthesizedType, ThisType, + TypeOperator, + IndexedAccessType, LiteralType, // Binding patterns ObjectBindingPattern, @@ -882,6 +885,18 @@ namespace ts { type: TypeNode; } + export interface TypeOperatorNode extends TypeNode { + kind: SyntaxKind.TypeOperator; + operator: SyntaxKind.KeyOfKeyword; + type: TypeNode; + } + + export interface IndexedAccessTypeNode extends TypeNode { + kind: SyntaxKind.IndexedAccessType; + objectType: TypeNode; + indexType: TypeNode; + } + export interface LiteralTypeNode extends TypeNode { kind: SyntaxKind.LiteralType; literal: Expression; @@ -953,10 +968,6 @@ namespace ts { operator: PostfixUnaryOperator; } - export interface PostfixExpression extends UnaryExpression { - _postfixExpressionBrand: any; - } - export interface LeftHandSideExpression extends IncrementExpression { _leftHandSideExpressionBrand: any; } @@ -2667,14 +2678,16 @@ namespace ts { Object = 1 << 15, // Object type Union = 1 << 16, // Union (T | U) Intersection = 1 << 17, // Intersection (T & U) + Index = 1 << 18, // keyof T + IndexedAccess = 1 << 19, // T[K] /* @internal */ - FreshLiteral = 1 << 18, // Fresh literal type + FreshLiteral = 1 << 20, // Fresh literal type /* @internal */ - ContainsWideningType = 1 << 19, // Type is or contains undefined or null widening type + ContainsWideningType = 1 << 21, // Type is or contains undefined or null widening type /* @internal */ - ContainsObjectLiteral = 1 << 20, // Type is or contains object literal type + ContainsObjectLiteral = 1 << 22, // Type is or contains object literal type /* @internal */ - ContainsAnyFunctionType = 1 << 21, // Type is or contains object literal type + ContainsAnyFunctionType = 1 << 23, // Type is or contains object literal type /* @internal */ Nullable = Undefined | Null, @@ -2697,7 +2710,7 @@ namespace ts { // 'Narrowable' types are types where narrowing actually narrows. // This *should* be every type other than null, undefined, void, and never - Narrowable = Any | StructuredType | TypeParameter | StringLike | NumberLike | BooleanLike | ESSymbol, + Narrowable = Any | StructuredType | TypeParameter | Index | IndexedAccess | StringLike | NumberLike | BooleanLike | ESSymbol, NotUnionOrUnit = Any | ESSymbol | Object, /* @internal */ RequiresWidening = ContainsWideningType | ContainsObjectLiteral, @@ -2860,9 +2873,22 @@ namespace ts { /* @internal */ resolvedApparentType: Type; /* @internal */ + resolvedIndexType: IndexType; + /* @internal */ + resolvedIndexedAccessTypes: IndexedAccessType[]; + /* @internal */ isThisType?: boolean; } + export interface IndexType extends Type { + type: TypeParameter; + } + + export interface IndexedAccessType extends Type { + objectType: Type; + indexType: TypeParameter; + } + export const enum SignatureKind { Call, Construct, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index d78418e1976db..299f91be6625c 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1619,29 +1619,51 @@ namespace ts { return node && node.dotDotDotToken !== undefined; } + export const enum AssignmentKind { + None, Definite, Compound + } + + export function getAssignmentTargetKind(node: Node): AssignmentKind { + let parent = node.parent; + while (true) { + switch (parent.kind) { + case SyntaxKind.BinaryExpression: + const binaryOperator = (parent).operatorToken.kind; + return isAssignmentOperator(binaryOperator) && (parent).left === node ? + binaryOperator === SyntaxKind.EqualsToken ? AssignmentKind.Definite : AssignmentKind.Compound : + AssignmentKind.None; + case SyntaxKind.PrefixUnaryExpression: + case SyntaxKind.PostfixUnaryExpression: + const unaryOperator = (parent).operator; + return unaryOperator === SyntaxKind.PlusPlusToken || unaryOperator === SyntaxKind.MinusMinusToken ? AssignmentKind.Compound : AssignmentKind.None; + case SyntaxKind.ForInStatement: + case SyntaxKind.ForOfStatement: + return (parent).initializer === node ? AssignmentKind.Definite : AssignmentKind.None; + case SyntaxKind.ParenthesizedExpression: + case SyntaxKind.ArrayLiteralExpression: + case SyntaxKind.SpreadElementExpression: + node = parent; + break; + case SyntaxKind.ShorthandPropertyAssignment: + if ((parent).name !== node) { + return AssignmentKind.None; + } + // Fall through + case SyntaxKind.PropertyAssignment: + node = parent.parent; + break; + default: + return AssignmentKind.None; + } + parent = node.parent; + } + } + // A node is an assignment target if it is on the left hand side of an '=' token, if it is parented by a property // assignment in an object literal that is an assignment target, or if it is parented by an array literal that is // an assignment target. Examples include 'a = xxx', '{ p: a } = xxx', '[{ p: a}] = xxx'. export function isAssignmentTarget(node: Node): boolean { - while (node.parent.kind === SyntaxKind.ParenthesizedExpression) { - node = node.parent; - } - while (true) { - const parent = node.parent; - if (parent.kind === SyntaxKind.ArrayLiteralExpression || parent.kind === SyntaxKind.SpreadElementExpression) { - node = parent; - continue; - } - if (parent.kind === SyntaxKind.PropertyAssignment || parent.kind === SyntaxKind.ShorthandPropertyAssignment) { - node = parent.parent; - continue; - } - return parent.kind === SyntaxKind.BinaryExpression && - isAssignmentOperator((parent).operatorToken.kind) && - (parent).left === node || - (parent.kind === SyntaxKind.ForInStatement || parent.kind === SyntaxKind.ForOfStatement) && - (parent).initializer === node; - } + return getAssignmentTargetKind(node) !== AssignmentKind.None; } export function isNodeDescendantOf(node: Node, ancestor: Node): boolean { diff --git a/tests/baselines/reference/ES5For-of12.errors.txt b/tests/baselines/reference/ES5For-of12.errors.txt index 02ed4c335a6e7..180a32bddb48e 100644 --- a/tests/baselines/reference/ES5For-of12.errors.txt +++ b/tests/baselines/reference/ES5For-of12.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-of12.ts(1,7): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/statements/for-ofStatements/ES5For-of12.ts(1,7): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ==== tests/cases/conformance/statements/for-ofStatements/ES5For-of12.ts (1 errors) ==== for ([""] of [[""]]) { } ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/abstractPropertyNegative.errors.txt b/tests/baselines/reference/abstractPropertyNegative.errors.txt index 448fb2255e0bb..314ab842ded14 100644 --- a/tests/baselines/reference/abstractPropertyNegative.errors.txt +++ b/tests/baselines/reference/abstractPropertyNegative.errors.txt @@ -6,7 +6,7 @@ tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstra tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'readonlyProp' from class 'B'. tests/cases/compiler/abstractPropertyNegative.ts(15,5): error TS1244: Abstract methods can only appear within an abstract class. tests/cases/compiler/abstractPropertyNegative.ts(16,37): error TS1005: '{' expected. -tests/cases/compiler/abstractPropertyNegative.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/abstractPropertyNegative.ts(19,3): error TS2540: Cannot assign to 'ro' because it is a constant or a read-only property. tests/cases/compiler/abstractPropertyNegative.ts(24,7): error TS2415: Class 'WrongTypePropertyImpl' incorrectly extends base class 'WrongTypeProperty'. Types of property 'num' are incompatible. Type 'string' is not assignable to type 'number'. @@ -58,8 +58,8 @@ tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors } let c = new C(); c.ro = "error: lhs of assignment can't be readonly"; - ~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~ +!!! error TS2540: Cannot assign to 'ro' because it is a constant or a read-only property. abstract class WrongTypeProperty { abstract num: number; diff --git a/tests/baselines/reference/arithAssignTyping.errors.txt b/tests/baselines/reference/arithAssignTyping.errors.txt index 10f34e94012f2..12b5b52698dbf 100644 --- a/tests/baselines/reference/arithAssignTyping.errors.txt +++ b/tests/baselines/reference/arithAssignTyping.errors.txt @@ -1,15 +1,15 @@ -tests/cases/compiler/arithAssignTyping.ts(3,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/compiler/arithAssignTyping.ts(4,1): error TS2365: Operator '+=' cannot be applied to types 'typeof f' and '1'. -tests/cases/compiler/arithAssignTyping.ts(5,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(6,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(7,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(8,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(9,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(10,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(11,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(12,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(13,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(14,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/compiler/arithAssignTyping.ts(3,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(4,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(5,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(6,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(7,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(8,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(9,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(10,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(11,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(12,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(13,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(14,1): error TS2539: Cannot assign to 'f' because it is not a variable. ==== tests/cases/compiler/arithAssignTyping.ts (12 errors) ==== @@ -17,37 +17,37 @@ tests/cases/compiler/arithAssignTyping.ts(14,1): error TS2362: The left-hand sid f += ''; // error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f += 1; // error - ~~~~~~ -!!! error TS2365: Operator '+=' cannot be applied to types 'typeof f' and '1'. + ~ +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f -= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f *= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f /= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f %= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f &= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f |= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f <<= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f >>= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f >>>= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f ^= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. \ No newline at end of file +!!! error TS2539: Cannot assign to 'f' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/assignAnyToEveryType.errors.txt b/tests/baselines/reference/assignAnyToEveryType.errors.txt index 9aae6efc37e44..86efb0c3019de 100644 --- a/tests/baselines/reference/assignAnyToEveryType.errors.txt +++ b/tests/baselines/reference/assignAnyToEveryType.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/any/assignAnyToEveryType.ts(41,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/any/assignAnyToEveryType.ts(41,1): error TS2539: Cannot assign to 'M' because it is not a variable. ==== tests/cases/conformance/types/any/assignAnyToEveryType.ts (1 errors) ==== @@ -44,7 +44,7 @@ tests/cases/conformance/types/any/assignAnyToEveryType.ts(41,1): error TS2364: I M = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. function k(a: T) { a = x; diff --git a/tests/baselines/reference/assignToEnum.errors.txt b/tests/baselines/reference/assignToEnum.errors.txt index d50daa3099f6a..438a002ef1ee9 100644 --- a/tests/baselines/reference/assignToEnum.errors.txt +++ b/tests/baselines/reference/assignToEnum.errors.txt @@ -1,22 +1,22 @@ -tests/cases/compiler/assignToEnum.ts(2,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/compiler/assignToEnum.ts(3,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/compiler/assignToEnum.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/assignToEnum.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/assignToEnum.ts(2,1): error TS2539: Cannot assign to 'A' because it is not a variable. +tests/cases/compiler/assignToEnum.ts(3,1): error TS2539: Cannot assign to 'A' because it is not a variable. +tests/cases/compiler/assignToEnum.ts(4,3): error TS2540: Cannot assign to 'foo' because it is a constant or a read-only property. +tests/cases/compiler/assignToEnum.ts(5,3): error TS2540: Cannot assign to 'foo' because it is a constant or a read-only property. ==== tests/cases/compiler/assignToEnum.ts (4 errors) ==== enum A { foo, bar } A = undefined; // invalid LHS ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'A' because it is not a variable. A = A.bar; // invalid LHS ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'A' because it is not a variable. A.foo = 1; // invalid LHS - ~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'foo' because it is a constant or a read-only property. A.foo = A.bar; // invalid LHS - ~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'foo' because it is a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/assignToExistingClass.errors.txt b/tests/baselines/reference/assignToExistingClass.errors.txt index 6a377df5b0c56..5f7faac9e64d7 100644 --- a/tests/baselines/reference/assignToExistingClass.errors.txt +++ b/tests/baselines/reference/assignToExistingClass.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/assignToExistingClass.ts(8,13): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/assignToExistingClass.ts(8,13): error TS2539: Cannot assign to 'Mocked' because it is not a variable. ==== tests/cases/compiler/assignToExistingClass.ts (1 errors) ==== @@ -11,7 +11,7 @@ tests/cases/compiler/assignToExistingClass.ts(8,13): error TS2364: Invalid left- willThrowError() { Mocked = Mocked || function () { // => Error: Invalid left-hand side of assignment expression. ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'Mocked' because it is not a variable. return { myProp: "test" }; }; } diff --git a/tests/baselines/reference/assignToInvalidLHS.errors.txt b/tests/baselines/reference/assignToInvalidLHS.errors.txt index a39756d15f7f8..b338871606b4f 100644 --- a/tests/baselines/reference/assignToInvalidLHS.errors.txt +++ b/tests/baselines/reference/assignToInvalidLHS.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/assignToInvalidLHS.ts(4,9): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/assignToInvalidLHS.ts(4,9): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ==== tests/cases/compiler/assignToInvalidLHS.ts (1 errors) ==== @@ -7,4 +7,4 @@ tests/cases/compiler/assignToInvalidLHS.ts(4,9): error TS2364: Invalid left-hand // Below is actually valid JavaScript (see http://es5.github.com/#x8.7 ), even though will always fail at runtime with 'invalid left-hand side' var x = new y = 5; ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentLHSIsValue.errors.txt b/tests/baselines/reference/assignmentLHSIsValue.errors.txt index f97ae2bcfa5c1..01de8d33441a5 100644 --- a/tests/baselines/reference/assignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/assignmentLHSIsValue.errors.txt @@ -1,42 +1,42 @@ -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(6,21): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7,13): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(8,21): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(11,18): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(13,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(19,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(22,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(24,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(27,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(28,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(29,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(30,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(31,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(32,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(6,21): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7,13): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(8,21): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(11,18): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(13,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(17,1): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(19,1): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(22,1): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(24,1): error TS2539: Cannot assign to 'foo' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(27,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(28,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(29,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(30,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(31,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(32,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(35,3): error TS7028: Unused label. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(35,9): error TS1128: Declaration or statement expected. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,2): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,6): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,2): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,6): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(42,36): error TS1034: 'super' must be followed by an argument list or member access. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(44,19): error TS1034: 'super' must be followed by an argument list or member access. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(46,27): error TS1034: 'super' must be followed by an argument list or member access. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(50,20): error TS1128: Declaration or statement expected. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(51,11): error TS1005: ';' expected. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(54,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(57,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(58,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(59,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(60,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(61,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(62,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(63,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(64,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(65,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(66,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(67,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(68,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(69,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(70,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(54,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(57,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(58,2): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(59,2): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(60,2): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(61,2): error TS2539: Cannot assign to 'foo' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(62,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(63,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(64,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(65,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(66,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(67,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(68,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(69,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(70,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ==== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts (39 errors) ==== @@ -47,61 +47,61 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7 class C { constructor() { this = value; } ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. foo() { this = value; } ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. static sfoo() { this = value; } ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. } function foo() { this = value; } ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. this = value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // identifiers: module, class, enum, function module M { export var a; } M = value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. C = value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. enum E { } E = value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'E' because it is not a variable. foo = value; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'foo' because it is not a variable. // literals null = value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. true = value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. false = value; ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. 0 = value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. '' = value; ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. /d+/ = value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // object literals { a: 0} = value; @@ -113,9 +113,9 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7 // array literals ['', ''] = value; ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // super class Derived extends C { @@ -143,48 +143,48 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7 // function calls foo() = value; ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // parentheses, the containted expression is value (this) = value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (M) = value; - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'M' because it is not a variable. (C) = value; - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'C' because it is not a variable. (E) = value; - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'E' because it is not a variable. (foo) = value; - ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~~~ +!!! error TS2539: Cannot assign to 'foo' because it is not a variable. (null) = value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (true) = value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (0) = value; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ('') = value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (/d+/) = value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ({}) = value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ([]) = value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (function baz() { }) = value; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (foo()) = value; ~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentToFunction.errors.txt b/tests/baselines/reference/assignmentToFunction.errors.txt index b9a2f1f267518..6e9b1b3c6ddbe 100644 --- a/tests/baselines/reference/assignmentToFunction.errors.txt +++ b/tests/baselines/reference/assignmentToFunction.errors.txt @@ -1,12 +1,12 @@ -tests/cases/compiler/assignmentToFunction.ts(2,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/compiler/assignmentToFunction.ts(8,9): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/assignmentToFunction.ts(2,1): error TS2539: Cannot assign to 'fn' because it is not a variable. +tests/cases/compiler/assignmentToFunction.ts(8,9): error TS2539: Cannot assign to 'bar' because it is not a variable. ==== tests/cases/compiler/assignmentToFunction.ts (2 errors) ==== function fn() { } fn = () => 3; ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'fn' because it is not a variable. module foo { function xyz() { @@ -14,6 +14,6 @@ tests/cases/compiler/assignmentToFunction.ts(8,9): error TS2364: Invalid left-ha } bar = null; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'bar' because it is not a variable. } } \ No newline at end of file diff --git a/tests/baselines/reference/assignmentToParenthesizedExpression1.errors.txt b/tests/baselines/reference/assignmentToParenthesizedExpression1.errors.txt index 0a411828bf939..ff8fa5d22b2ea 100644 --- a/tests/baselines/reference/assignmentToParenthesizedExpression1.errors.txt +++ b/tests/baselines/reference/assignmentToParenthesizedExpression1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/assignmentToParenthesizedExpression1.ts(2,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/assignmentToParenthesizedExpression1.ts(2,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/compiler/assignmentToParenthesizedExpression1.ts(2,2): error TS2695: Left side of comma operator is unused and has no side effects. @@ -6,6 +6,6 @@ tests/cases/compiler/assignmentToParenthesizedExpression1.ts(2,2): error TS2695: var x; (1, x)=0; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ~ !!! error TS2695: Left side of comma operator is unused and has no side effects. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentToParenthesizedIdentifiers.errors.txt b/tests/baselines/reference/assignmentToParenthesizedIdentifiers.errors.txt index b929704880ecd..907fcce4c315b 100644 --- a/tests/baselines/reference/assignmentToParenthesizedIdentifiers.errors.txt +++ b/tests/baselines/reference/assignmentToParenthesizedIdentifiers.errors.txt @@ -3,9 +3,9 @@ tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesize tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(13,1): error TS2322: Type '""' is not assignable to type 'number'. tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(14,1): error TS2322: Type '""' is not assignable to type 'number'. tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(15,1): error TS2322: Type '""' is not assignable to type 'number'. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(18,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(25,5): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(17,1): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(18,2): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(25,5): error TS2539: Cannot assign to 'M3' because it is not a variable. tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(31,1): error TS2322: Type '{ x: string; }' is not assignable to type 'typeof M3'. Types of property 'x' are incompatible. Type 'string' is not assignable to type 'number'. @@ -15,8 +15,8 @@ tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesize tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(33,1): error TS2322: Type '{ x: string; }' is not assignable to type 'typeof M3'. Types of property 'x' are incompatible. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(37,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(38,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(37,1): error TS2539: Cannot assign to 'fn' because it is not a variable. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(38,2): error TS2539: Cannot assign to 'fn' because it is not a variable. tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(43,5): error TS2322: Type '""' is not assignable to type 'number'. tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(44,5): error TS2322: Type '""' is not assignable to type 'number'. tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(48,5): error TS2322: Type '""' is not assignable to type 'number'. @@ -24,10 +24,10 @@ tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesize tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(54,5): error TS2322: Type '""' is not assignable to type 'number'. tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(55,5): error TS2322: Type '""' is not assignable to type 'number'. tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(56,5): error TS2322: Type '""' is not assignable to type 'number'. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(62,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(63,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(69,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(70,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(62,1): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(63,2): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(69,1): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(70,2): error TS2539: Cannot assign to 'C' because it is not a variable. ==== tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts (24 errors) ==== @@ -59,10 +59,10 @@ tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesize M = { y: 3 }; // Error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. (M) = { y: 3 }; // Error - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'M' because it is not a variable. module M2 { export module M3 { @@ -71,7 +71,7 @@ tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesize M3 = { x: 3 }; // Error ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M3' because it is not a variable. } M2.M3 = { x: 3 }; // OK (M2).M3 = { x: 3 }; // OK @@ -97,10 +97,10 @@ tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesize function fn() { } fn = () => 3; // Bug 823548: Should be error (fn is not a reference) ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'fn' because it is not a variable. (fn) = () => 3; // Should be error - ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~~ +!!! error TS2539: Cannot assign to 'fn' because it is not a variable. function fn2(x: number, y: { t: number }) { x = 3; @@ -140,10 +140,10 @@ tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesize } E = undefined; // Error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'E' because it is not a variable. (E) = undefined; // Error - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'E' because it is not a variable. class C { @@ -151,8 +151,8 @@ tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesize C = undefined; // Error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. (C) = undefined; // Error - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'C' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentToReferenceTypes.errors.txt b/tests/baselines/reference/assignmentToReferenceTypes.errors.txt index 56d6adc41499f..7e323479d57b1 100644 --- a/tests/baselines/reference/assignmentToReferenceTypes.errors.txt +++ b/tests/baselines/reference/assignmentToReferenceTypes.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/assignmentToReferenceTypes.ts(5,1): error TS2304: Cannot find name 'M'. -tests/cases/compiler/assignmentToReferenceTypes.ts(9,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/compiler/assignmentToReferenceTypes.ts(13,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/compiler/assignmentToReferenceTypes.ts(16,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/assignmentToReferenceTypes.ts(9,1): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/compiler/assignmentToReferenceTypes.ts(13,1): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/compiler/assignmentToReferenceTypes.ts(16,1): error TS2539: Cannot assign to 'f' because it is not a variable. ==== tests/cases/compiler/assignmentToReferenceTypes.ts (4 errors) ==== @@ -17,18 +17,18 @@ tests/cases/compiler/assignmentToReferenceTypes.ts(16,1): error TS2364: Invalid } C = null; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. enum E { } E = null; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'E' because it is not a variable. function f() { } f = null; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. var x = 1; x = null; diff --git a/tests/baselines/reference/assignments.errors.txt b/tests/baselines/reference/assignments.errors.txt index 2e637a6c720a0..86bbe75cd4b77 100644 --- a/tests/baselines/reference/assignments.errors.txt +++ b/tests/baselines/reference/assignments.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(11,1): error TS2304: Cannot find name 'M'. -tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(14,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(21,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(14,1): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(17,1): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(18,3): error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. +tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(21,1): error TS2539: Cannot assign to 'fn' because it is not a variable. tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): error TS2693: 'I' only refers to a type, but is being used as a value here. @@ -24,20 +24,20 @@ tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): er class C { } C = null; // Error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. enum E { A } E = null; // Error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'E' because it is not a variable. E.A = null; // OK per spec, Error per implementation (509581) - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. function fn() { } fn = null; // Should be error ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'fn' because it is not a variable. var v; v = null; // OK diff --git a/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt b/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt index 61f893ba88fa5..bc6bb41b27f4f 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt @@ -1,37 +1,37 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(8,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(9,9): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(9,9): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(12,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(13,9): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(13,9): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(16,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(17,9): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(22,5): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(23,5): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(26,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(27,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(31,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(32,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(34,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(35,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(38,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(39,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(41,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(42,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(45,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(46,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(17,9): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(22,5): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(23,5): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(26,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(27,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(31,1): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(32,1): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(34,1): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(35,1): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(38,1): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(39,1): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(41,1): error TS2539: Cannot assign to 'foo' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(42,1): error TS2539: Cannot assign to 'foo' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(45,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(46,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(47,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(48,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(48,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(49,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(50,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(51,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(52,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(50,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(51,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(52,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(53,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(54,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(54,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(55,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(56,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(56,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(59,9): error TS1128: Declaration or statement expected. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(60,9): error TS1128: Declaration or statement expected. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(63,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(64,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(64,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(70,15): error TS1034: 'super' must be followed by an argument list or member access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(71,15): error TS1034: 'super' must be followed by an argument list or member access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(75,15): error TS1034: 'super' must be followed by an argument list or member access. @@ -43,35 +43,35 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(88,11): error TS1005: ';' expected. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(89,11): error TS1005: ';' expected. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(92,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(93,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(96,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(97,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(98,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(99,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(100,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(101,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(102,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(103,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(104,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(105,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(106,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(107,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(93,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(96,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(97,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(98,2): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(99,2): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(100,2): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(101,2): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(102,2): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(103,2): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(104,2): error TS2539: Cannot assign to 'foo' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(105,2): error TS2539: Cannot assign to 'foo' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(106,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(107,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(108,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(109,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(110,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(111,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(109,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(110,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(111,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(112,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(113,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(113,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(114,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(115,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(115,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(116,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(117,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(117,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(118,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(119,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(119,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(120,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(121,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(121,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(122,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(123,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(123,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ==== tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts (74 errors) ==== @@ -87,7 +87,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. this += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. } foo() { this *= value; @@ -95,7 +95,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. this += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. } static sfoo() { this *= value; @@ -103,94 +103,94 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. this += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. } } function foo() { this *= value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. this += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. } this *= value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. this += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // identifiers: module, class, enum, function module M { export var a; } M *= value; ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. M += value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. C *= value; ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. C += value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. enum E { } E *= value; ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'E' because it is not a variable. E += value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'E' because it is not a variable. foo *= value; ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'foo' because it is not a variable. foo += value; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'foo' because it is not a variable. // literals null *= value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. null += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. true *= value; ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. true += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. false *= value; ~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. false += value; ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. 0 *= value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. 0 += value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. '' *= value; ~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. '' += value; ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. /d+/ *= value; ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. /d+/ += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // object literals { a: 0} *= value; @@ -206,7 +206,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. ['', ''] += value; ~~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // super class Derived extends C { @@ -259,90 +259,90 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. foo() += value; ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // parentheses, the containted expression is value (this) *= value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (this) += value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (M) *= value; - ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2539: Cannot assign to 'M' because it is not a variable. (M) += value; - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'M' because it is not a variable. (C) *= value; - ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2539: Cannot assign to 'C' because it is not a variable. (C) += value; - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'C' because it is not a variable. (E) *= value; - ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2539: Cannot assign to 'E' because it is not a variable. (E) += value; - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'E' because it is not a variable. (foo) *= value; - ~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~~~ +!!! error TS2539: Cannot assign to 'foo' because it is not a variable. (foo) += value; - ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~~~ +!!! error TS2539: Cannot assign to 'foo' because it is not a variable. (null) *= value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (null) += value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (true) *= value; ~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. (true) += value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (0) *= value; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (0) += value; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ('') *= value; ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. ('') += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (/d+/) *= value; ~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. (/d+/) += value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ({}) *= value; ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. ({}) += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ([]) *= value; ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. ([]) += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (function baz1() { }) *= value; ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. (function baz2() { }) += value; ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (foo()) *= value; ~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. (foo()) += value; ~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt index 0d9bab910ef88..22eeb18ac4ad1 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt @@ -1,16 +1,16 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(7,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(10,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(13,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(18,5): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(21,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(25,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(27,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(30,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(32,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(35,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(18,5): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(21,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(25,1): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(27,1): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(30,1): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(32,1): error TS2539: Cannot assign to 'foo' because it is not a variable. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(35,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(36,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(37,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(38,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(38,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(39,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(40,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(43,3): error TS7028: Unused label. @@ -22,14 +22,14 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(65,21): error TS1128: Declaration or statement expected. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(66,11): error TS1005: ';' expected. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(69,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(72,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(73,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(74,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(75,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(76,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(77,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(72,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(73,2): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(74,2): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(75,2): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(76,2): error TS2539: Cannot assign to 'foo' because it is not a variable. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(77,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(78,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(79,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(79,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(80,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(81,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(82,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. @@ -64,36 +64,36 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm function foo() { this **= value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. } this **= value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // identifiers: module, class, enum, function module M { export var a; } M **= value; ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. C **= value; ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. enum E { } E **= value; ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'E' because it is not a variable. foo **= value; ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'foo' because it is not a variable. // literals null **= value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. true **= value; ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. @@ -102,7 +102,7 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. 0 **= value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. '' **= value; ~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. @@ -160,28 +160,28 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm // parentheses, the containted expression is value (this) **= value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (M) **= value; - ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2539: Cannot assign to 'M' because it is not a variable. (C) **= value; - ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2539: Cannot assign to 'C' because it is not a variable. (E) **= value; - ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2539: Cannot assign to 'E' because it is not a variable. (foo) **= value; - ~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~~~ +!!! error TS2539: Cannot assign to 'foo' because it is not a variable. (null) **= value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (true) **= value; ~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. (0) **= value; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ('') **= value; ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. diff --git a/tests/baselines/reference/concatClassAndString.errors.txt b/tests/baselines/reference/concatClassAndString.errors.txt index 623c213181f9a..b0cb54b31c075 100644 --- a/tests/baselines/reference/concatClassAndString.errors.txt +++ b/tests/baselines/reference/concatClassAndString.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/concatClassAndString.ts(4,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/concatClassAndString.ts(4,1): error TS2539: Cannot assign to 'f' because it is not a variable. ==== tests/cases/compiler/concatClassAndString.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/compiler/concatClassAndString.ts(4,1): error TS2364: Invalid left-ha f += ''; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access.errors.txt b/tests/baselines/reference/constDeclarations-access.errors.txt index 3c748cc4a5ff5..81121b6fe5ceb 100644 --- a/tests/baselines/reference/constDeclarations-access.errors.txt +++ b/tests/baselines/reference/constDeclarations-access.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/file2.ts(1,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/file2.ts(1,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ==== tests/cases/compiler/file1.ts (0 errors) ==== @@ -8,4 +8,4 @@ tests/cases/compiler/file2.ts(1,1): error TS2449: The operand of an increment or ==== tests/cases/compiler/file2.ts (1 errors) ==== x++; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. \ No newline at end of file +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access2.errors.txt b/tests/baselines/reference/constDeclarations-access2.errors.txt index 667f490a374a1..16335bfa59cbe 100644 --- a/tests/baselines/reference/constDeclarations-access2.errors.txt +++ b/tests/baselines/reference/constDeclarations-access2.errors.txt @@ -1,20 +1,20 @@ -tests/cases/compiler/constDeclarations-access2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(19,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(21,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(5,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(6,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(7,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(8,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(9,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(10,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(11,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(12,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(13,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(14,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(15,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(16,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(18,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(19,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(20,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(21,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(23,5): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ==== tests/cases/compiler/constDeclarations-access2.ts (17 errors) ==== @@ -24,57 +24,57 @@ tests/cases/compiler/constDeclarations-access2.ts(23,3): error TS2449: The opera // Errors x = 1; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x += 2; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x -= 3; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x *= 4; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x /= 5; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x %= 6; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x <<= 7; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x >>= 8; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x >>>= 9; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x &= 10; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x |= 11; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x ^= 12; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x++; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x--; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ++x; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. --x; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ++((x)); - ~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. // OK var a = x + 1; diff --git a/tests/baselines/reference/constDeclarations-access3.errors.txt b/tests/baselines/reference/constDeclarations-access3.errors.txt index a6cb124d28c57..03ea2d29bba92 100644 --- a/tests/baselines/reference/constDeclarations-access3.errors.txt +++ b/tests/baselines/reference/constDeclarations-access3.errors.txt @@ -1,21 +1,21 @@ -tests/cases/compiler/constDeclarations-access3.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(8,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(9,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(10,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(11,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(12,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(13,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(14,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(15,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(16,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(17,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(18,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(19,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(21,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(22,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(23,5): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(24,5): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(26,7): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(28,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ==== tests/cases/compiler/constDeclarations-access3.ts (18 errors) ==== @@ -27,62 +27,62 @@ tests/cases/compiler/constDeclarations-access3.ts(28,1): error TS2450: Left-hand // Errors M.x = 1; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x += 2; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x -= 3; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x *= 4; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x /= 5; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x %= 6; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x <<= 7; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x >>= 8; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x >>>= 9; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x &= 10; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x |= 11; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x ^= 12; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x++; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x--; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ++M.x; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. --M.x; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ++((M.x)); - ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M["x"] = 0; - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. // OK var a = M.x + 1; diff --git a/tests/baselines/reference/constDeclarations-access4.errors.txt b/tests/baselines/reference/constDeclarations-access4.errors.txt index 3d7d4a704a81e..a4111c2d7023c 100644 --- a/tests/baselines/reference/constDeclarations-access4.errors.txt +++ b/tests/baselines/reference/constDeclarations-access4.errors.txt @@ -1,21 +1,21 @@ -tests/cases/compiler/constDeclarations-access4.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(8,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(9,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(10,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(11,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(12,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(13,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(14,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(15,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(16,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(17,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(18,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(19,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(21,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(22,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(23,5): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(24,5): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(26,7): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(28,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ==== tests/cases/compiler/constDeclarations-access4.ts (18 errors) ==== @@ -27,62 +27,62 @@ tests/cases/compiler/constDeclarations-access4.ts(28,1): error TS2450: Left-hand // Errors M.x = 1; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x += 2; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x -= 3; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x *= 4; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x /= 5; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x %= 6; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x <<= 7; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x >>= 8; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x >>>= 9; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x &= 10; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x |= 11; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x ^= 12; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x++; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x--; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ++M.x; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. --M.x; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ++((M.x)); - ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M["x"] = 0; - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. // OK var a = M.x + 1; diff --git a/tests/baselines/reference/constDeclarations-access5.errors.txt b/tests/baselines/reference/constDeclarations-access5.errors.txt index 45160bbc7cede..316465e80b85b 100644 --- a/tests/baselines/reference/constDeclarations-access5.errors.txt +++ b/tests/baselines/reference/constDeclarations-access5.errors.txt @@ -1,21 +1,21 @@ -tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(17,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(19,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(4,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(5,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(6,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(7,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(8,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(9,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(10,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(11,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(12,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(13,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(14,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(15,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(17,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(18,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(19,5): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(20,5): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(22,7): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(24,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ==== tests/cases/compiler/constDeclarations_access_2.ts (18 errors) ==== @@ -23,62 +23,62 @@ tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-han import m = require('constDeclarations_access_1'); // Errors m.x = 1; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x += 2; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x -= 3; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x *= 4; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x /= 5; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x %= 6; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x <<= 7; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x >>= 8; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x >>>= 9; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x &= 10; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x |= 11; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x ^= 12; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m m.x++; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x--; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ++m.x; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. --m.x; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ++((m.x)); - ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m["x"] = 0; - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. // OK var a = m.x + 1; diff --git a/tests/baselines/reference/constDeclarations-errors.errors.txt b/tests/baselines/reference/constDeclarations-errors.errors.txt index 2c9c17cc102f9..ace4cd7b25f27 100644 --- a/tests/baselines/reference/constDeclarations-errors.errors.txt +++ b/tests/baselines/reference/constDeclarations-errors.errors.txt @@ -5,7 +5,7 @@ tests/cases/compiler/constDeclarations-errors.ts(5,11): error TS1155: 'const' de tests/cases/compiler/constDeclarations-errors.ts(5,15): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(5,27): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(10,19): error TS2365: Operator '<' cannot be applied to types '0' and '1'. -tests/cases/compiler/constDeclarations-errors.ts(10,27): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-errors.ts(10,27): error TS2540: Cannot assign to 'c8' because it is a constant or a read-only property. tests/cases/compiler/constDeclarations-errors.ts(13,11): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(16,20): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(16,25): error TS2365: Operator '<' cannot be applied to types '0' and '1'. @@ -37,7 +37,7 @@ tests/cases/compiler/constDeclarations-errors.ts(16,25): error TS2365: Operator ~~~~~~ !!! error TS2365: Operator '<' cannot be applied to types '0' and '1'. ~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'c8' because it is a constant or a read-only property. // error, can not be unintalized for(const c9; c9 < 1;) { } diff --git a/tests/baselines/reference/constEnumBadPropertyNames.errors.txt b/tests/baselines/reference/constEnumBadPropertyNames.errors.txt index f2330617dea18..09610ca24e57a 100644 --- a/tests/baselines/reference/constEnumBadPropertyNames.errors.txt +++ b/tests/baselines/reference/constEnumBadPropertyNames.errors.txt @@ -1,8 +1,8 @@ -tests/cases/compiler/constEnumBadPropertyNames.ts(2,11): error TS2479: Property 'B' does not exist on 'const' enum 'E'. +tests/cases/compiler/constEnumBadPropertyNames.ts(2,11): error TS2339: Property 'B' does not exist on type 'typeof E'. ==== tests/cases/compiler/constEnumBadPropertyNames.ts (1 errors) ==== const enum E { A } var x = E["B"] ~~~ -!!! error TS2479: Property 'B' does not exist on 'const' enum 'E'. \ No newline at end of file +!!! error TS2339: Property 'B' does not exist on type 'typeof E'. \ No newline at end of file diff --git a/tests/baselines/reference/constEnumPropertyAccess2.errors.txt b/tests/baselines/reference/constEnumPropertyAccess2.errors.txt index ef5dd331d327f..9f16059ff2fc2 100644 --- a/tests/baselines/reference/constEnumPropertyAccess2.errors.txt +++ b/tests/baselines/reference/constEnumPropertyAccess2.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(14,9): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment. tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(15,12): error TS2476: A const enum member can only be accessed using a string literal. tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(17,1): error TS2322: Type '"string"' is not assignable to type 'G'. -tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(19,3): error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. ==== tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts (4 errors) ==== @@ -30,6 +30,6 @@ tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(19,1): error TS24 !!! error TS2322: Type '"string"' is not assignable to type 'G'. function foo(x: G) { } G.B = 3; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/constIndexedAccess.types b/tests/baselines/reference/constIndexedAccess.types index 0740a6efc67fb..9e08cf08f4983 100644 --- a/tests/baselines/reference/constIndexedAccess.types +++ b/tests/baselines/reference/constIndexedAccess.types @@ -76,16 +76,16 @@ enum numbersNotConst { } let s3 = test[numbersNotConst.zero]; ->s3 : any ->test[numbersNotConst.zero] : any +>s3 : string +>test[numbersNotConst.zero] : string >test : indexAccess >numbersNotConst.zero : numbersNotConst.zero >numbersNotConst : typeof numbersNotConst >zero : numbersNotConst.zero let n3 = test[numbersNotConst.one]; ->n3 : any ->test[numbersNotConst.one] : any +>n3 : number +>test[numbersNotConst.one] : number >test : indexAccess >numbersNotConst.one : numbersNotConst.one >numbersNotConst : typeof numbersNotConst diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt index 49d3e3788551f..2854e73d935d8 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt @@ -25,7 +25,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(59,5): error TS1 tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(70,13): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(73,37): error TS1127: Invalid character. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(82,13): error TS1109: Expression expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(90,23): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(90,23): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(91,13): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(106,29): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(107,13): error TS1109: Expression expected. @@ -236,7 +236,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(262,1): error TS // var any = 0 ^= ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. var bool = 0; ~~~ !!! error TS1109: Expression expected. diff --git a/tests/baselines/reference/decrementAndIncrementOperators.errors.txt b/tests/baselines/reference/decrementAndIncrementOperators.errors.txt index ec58db836a631..f8a0b5dcd829b 100644 --- a/tests/baselines/reference/decrementAndIncrementOperators.errors.txt +++ b/tests/baselines/reference/decrementAndIncrementOperators.errors.txt @@ -1,16 +1,16 @@ -tests/cases/compiler/decrementAndIncrementOperators.ts(4,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(6,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(7,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(9,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(10,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(12,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(13,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(15,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(16,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(18,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(19,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(21,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(22,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/decrementAndIncrementOperators.ts(4,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(6,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(7,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(9,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(10,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(12,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(13,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(15,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(16,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(18,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(19,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(21,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(22,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ==== tests/cases/compiler/decrementAndIncrementOperators.ts (13 errors) ==== @@ -19,49 +19,49 @@ tests/cases/compiler/decrementAndIncrementOperators.ts(22,3): error TS2357: The // errors 1 ++; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. (1)++; ~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. (1)--; ~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ++(1); ~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. --(1); ~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. (1 + 2)++; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. (1 + 2)--; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ++(1 + 2); ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. --(1 + 2); ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. (x + x)++; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. (x + x)--; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ++(x + x); ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. --(x + x); ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. //OK x++; diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt index 2e1d594164d91..e42b6ff67b42c 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt @@ -1,36 +1,36 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(24,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(25,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(26,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(25,25): error TS2539: Cannot assign to 'A' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(26,25): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(27,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(28,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(30,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(31,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(32,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(31,23): error TS2539: Cannot assign to 'A' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(32,23): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(33,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(34,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(37,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(38,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(39,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(39,26): error TS2539: Cannot assign to 'undefined' because it is not a variable. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(41,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(42,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(43,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(46,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(47,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(48,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(43,24): error TS2539: Cannot assign to 'undefined' because it is not a variable. +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 TS2365: Operator '+' cannot be applied to types 'undefined' 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, property or indexer. +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 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, property or indexer. +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 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, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(55,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(56,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +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 TS2365: Operator '+' cannot be applied to types 'undefined' 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, property or indexer. +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 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, property or indexer. +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 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. @@ -79,10 +79,10 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. var ResultIsNumber2 = --A; ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'A' because it is not a variable. var ResultIsNumber3 = --M; ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. var ResultIsNumber4 = --obj; ~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -95,10 +95,10 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. var ResultIsNumber7 = A--; ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'A' because it is not a variable. var ResultIsNumber8 = M--; ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. var ResultIsNumber9 = obj--; ~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -115,7 +115,7 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. var ResultIsNumber13 = --undefined; ~~~~~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'undefined' because it is not a variable. var ResultIsNumber14 = null--; ~~~~ @@ -125,28 +125,28 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. var ResultIsNumber16 = undefined--; ~~~~~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'undefined' because it is not a variable. // any type expressions var ResultIsNumber17 = --foo(); ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber18 = --A.foo(); ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber19 = --(null + undefined); ~~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber20 = --(null + null); ~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~ !!! 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, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber22 = --obj1.x; @@ -158,23 +158,23 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp var ResultIsNumber24 = foo()--; ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber25 = A.foo()--; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber26 = (null + undefined)--; ~~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber27 = (null + null)--; ~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~ !!! 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, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber29 = obj1.x--; diff --git a/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt b/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt index 29e06bc6a4e54..aae28d5e417b2 100644 --- a/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt +++ b/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(6,25): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(7,23): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(10,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(12,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(6,31): error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(7,29): error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(10,9): error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(12,1): error TS2542: Index signature in type 'typeof ENUM1' only permits reading. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(12,7): error TS2304: Cannot find name 'A'. @@ -12,19 +12,19 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp // expression var ResultIsNumber1 = --ENUM1["A"]; - ~~~~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. var ResultIsNumber2 = ENUM1.A--; - ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. // miss assignment operator --ENUM1["A"]; - ~~~~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. ENUM1[A]--; ~~~~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2542: Index signature in type 'typeof ENUM1' only permits reading. ~ !!! error TS2304: Cannot find name 'A'. \ No newline at end of file diff --git a/tests/baselines/reference/decrementOperatorWithEnumTypeInvalidOperations.errors.txt b/tests/baselines/reference/decrementOperatorWithEnumTypeInvalidOperations.errors.txt index 079bb2a6b640c..0a79432c59cf9 100644 --- a/tests/baselines/reference/decrementOperatorWithEnumTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/decrementOperatorWithEnumTypeInvalidOperations.errors.txt @@ -1,15 +1,15 @@ -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(7,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(8,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(10,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(11,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(14,25): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(7,25): error TS2539: Cannot assign to 'ENUM' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(8,25): error TS2539: Cannot assign to 'ENUM1' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(10,23): error TS2539: Cannot assign to 'ENUM' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(11,23): error TS2539: Cannot assign to 'ENUM1' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(14,25): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(14,43): error TS2339: Property 'B' does not exist on type 'typeof ENUM'. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(15,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(15,23): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(15,29): error TS2339: Property 'A' does not exist on type 'typeof ENUM'. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(18,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(19,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(21,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(22,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(18,3): error TS2539: Cannot assign to 'ENUM' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(19,3): error TS2539: Cannot assign to 'ENUM1' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(21,1): error TS2539: Cannot assign to 'ENUM' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(22,1): error TS2539: Cannot assign to 'ENUM1' because it is not a variable. ==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts (12 errors) ==== @@ -21,41 +21,41 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp // enum type var var ResultIsNumber1 = --ENUM; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM' because it is not a variable. var ResultIsNumber2 = --ENUM1; ~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM1' because it is not a variable. var ResultIsNumber3 = ENUM--; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM' because it is not a variable. var ResultIsNumber4 = ENUM1--; ~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM1' because it is not a variable. // enum type expressions var ResultIsNumber5 = --(ENUM["A"] + ENUM.B); ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~ !!! error TS2339: Property 'B' does not exist on type 'typeof ENUM'. var ResultIsNumber6 = (ENUM.A + ENUM["B"])--; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~ !!! error TS2339: Property 'A' does not exist on type 'typeof ENUM'. // miss assignment operator --ENUM; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM' because it is not a variable. --ENUM1; ~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM1' because it is not a variable. ENUM--; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM' because it is not a variable. ENUM1--; ~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. \ No newline at end of file +!!! error TS2539: Cannot assign to 'ENUM1' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/decrementOperatorWithNumberTypeInvalidOperations.errors.txt b/tests/baselines/reference/decrementOperatorWithNumberTypeInvalidOperations.errors.txt index 8df7e50809961..8cf459cb79033 100644 --- a/tests/baselines/reference/decrementOperatorWithNumberTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/decrementOperatorWithNumberTypeInvalidOperations.errors.txt @@ -1,23 +1,23 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(18,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(19,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(22,25): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(22,25): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(23,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(24,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(26,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(26,23): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(27,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(28,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(31,25): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(32,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(33,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(35,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(36,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(37,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(40,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(31,25): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(32,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/decrementOperatorWithNumberTypeInvalidOperations.ts(33,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/decrementOperatorWithNumberTypeInvalidOperations.ts(35,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/decrementOperatorWithNumberTypeInvalidOperations.ts(36,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/decrementOperatorWithNumberTypeInvalidOperations.ts(37,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/decrementOperatorWithNumberTypeInvalidOperations.ts(40,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(41,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(42,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(44,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(42,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(44,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(45,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(46,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(46,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts (20 errors) ==== @@ -48,7 +48,7 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp // number type literal var ResultIsNumber3 = --1; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber4 = --{ x: 1, y: 2}; ~~~~~~~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -58,7 +58,7 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp var ResultIsNumber6 = 1--; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber7 = { x: 1, y: 2 }--; ~~~~~~~~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -69,41 +69,41 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp // number type expressions var ResultIsNumber9 = --foo(); ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber10 = --A.foo(); ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber11 = --(NUMBER + NUMBER); ~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber12 = foo()--; ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber13 = A.foo()--; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber14 = (NUMBER + NUMBER)--; ~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. // miss assignment operator --1; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. --NUMBER1; ~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. --foo(); ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. 1--; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. NUMBER1--; ~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. foo()--; ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. \ No newline at end of file +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/enumLiteralTypes1.types b/tests/baselines/reference/enumLiteralTypes1.types index 754574f547cd2..b2a466c777de0 100644 --- a/tests/baselines/reference/enumLiteralTypes1.types +++ b/tests/baselines/reference/enumLiteralTypes1.types @@ -209,11 +209,11 @@ function f4(a: Choice.Yes, b: YesNo) { a++; >a++ : number ->a : Choice.Yes +>a : Choice b++; >b++ : number ->b : YesNo +>b : Choice } declare function g(x: Choice.Yes): string; diff --git a/tests/baselines/reference/enumLiteralTypes2.types b/tests/baselines/reference/enumLiteralTypes2.types index e27410a4dc710..6b881bee8c30c 100644 --- a/tests/baselines/reference/enumLiteralTypes2.types +++ b/tests/baselines/reference/enumLiteralTypes2.types @@ -210,7 +210,7 @@ function f4(a: Choice.Yes, b: UnknownYesNo) { a++; >a++ : number ->a : Choice.Yes +>a : Choice b++; >b++ : number diff --git a/tests/baselines/reference/externalModuleImmutableBindings.errors.txt b/tests/baselines/reference/externalModuleImmutableBindings.errors.txt index c8c61b2dc816b..815b5847458e1 100644 --- a/tests/baselines/reference/externalModuleImmutableBindings.errors.txt +++ b/tests/baselines/reference/externalModuleImmutableBindings.errors.txt @@ -1,23 +1,23 @@ -tests/cases/compiler/f2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/f2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/f2.ts(7,7): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(8,7): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. tests/cases/compiler/f2.ts(9,7): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. -tests/cases/compiler/f2.ts(12,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/f2.ts(13,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/f2.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/f2.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/f2.ts(12,7): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(13,7): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(17,8): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(18,8): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. tests/cases/compiler/f2.ts(19,8): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. -tests/cases/compiler/f2.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/f2.ts(23,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/f2.ts(27,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. -tests/cases/compiler/f2.ts(28,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. -tests/cases/compiler/f2.ts(29,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. -tests/cases/compiler/f2.ts(30,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. +tests/cases/compiler/f2.ts(22,8): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(23,8): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(27,12): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(28,12): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(29,12): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(30,12): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. tests/cases/compiler/f2.ts(31,12): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. tests/cases/compiler/f2.ts(32,12): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. -tests/cases/compiler/f2.ts(36,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. -tests/cases/compiler/f2.ts(37,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. -tests/cases/compiler/f2.ts(38,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. -tests/cases/compiler/f2.ts(39,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. +tests/cases/compiler/f2.ts(36,13): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(37,13): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(38,13): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(39,13): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. tests/cases/compiler/f2.ts(40,13): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. tests/cases/compiler/f2.ts(41,13): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. @@ -33,57 +33,57 @@ tests/cases/compiler/f2.ts(41,13): error TS2339: Property 'blah' does not exist var n = 'baz'; stuff.x = 0; - ~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. stuff['x'] = 1; - ~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. stuff.blah = 2; ~~~~ !!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. stuff[n] = 3; stuff.x++; - ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. stuff['x']++; - ~~~~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. stuff['blah']++; stuff[n]++; (stuff.x) = 0; - ~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. (stuff['x']) = 1; - ~~~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. (stuff.blah) = 2; ~~~~ !!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. (stuff[n]) = 3; (stuff.x)++; - ~~~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. (stuff['x'])++; - ~~~~~~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. (stuff['blah'])++; (stuff[n])++; for (stuff.x in []) {} - ~~~~~~~ -!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. for (stuff.x of []) {} - ~~~~~~~ -!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. for (stuff['x'] in []) {} - ~~~~~~~~~~ -!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. for (stuff['x'] of []) {} - ~~~~~~~~~~ -!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. for (stuff.blah in []) {} ~~~~ !!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. @@ -94,17 +94,17 @@ tests/cases/compiler/f2.ts(41,13): error TS2339: Property 'blah' does not exist for (stuff[n] of []) {} for ((stuff.x) in []) {} - ~~~~~~~~~ -!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. for ((stuff.x) of []) {} - ~~~~~~~~~ -!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. for ((stuff['x']) in []) {} - ~~~~~~~~~~~~ -!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. for ((stuff['x']) of []) {} - ~~~~~~~~~~~~ -!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. for ((stuff.blah) in []) {} ~~~~ !!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. diff --git a/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt b/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt index 6886d992bb2e5..03361cfcfab09 100644 --- a/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt +++ b/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(5,14): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. +tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(5,16): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(6,16): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(7,9): error TS2365: Operator '===' cannot be applied to types 'string' and 'number'. tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(9,16): error TS2339: Property 'unknownProperty' does not exist on type 'string'. @@ -12,7 +12,7 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors. for (let x in a) { let a1 = a[x + 1]; - ~~~~~~~~ + ~~~~~ !!! error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. let a2 = a[x - 1]; ~ diff --git a/tests/baselines/reference/for-of2.errors.txt b/tests/baselines/reference/for-of2.errors.txt index f4f39f60f670b..1975f8be0afad 100644 --- a/tests/baselines/reference/for-of2.errors.txt +++ b/tests/baselines/reference/for-of2.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/for-ofStatements/for-of2.ts(1,7): error TS1155: 'const' declarations must be initialized -tests/cases/conformance/es6/for-ofStatements/for-of2.ts(2,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. +tests/cases/conformance/es6/for-ofStatements/for-of2.ts(2,6): error TS2540: Cannot assign to 'v' because it is a constant or a read-only property. ==== tests/cases/conformance/es6/for-ofStatements/for-of2.ts (2 errors) ==== @@ -8,4 +8,4 @@ tests/cases/conformance/es6/for-ofStatements/for-of2.ts(2,6): error TS2485: The !!! error TS1155: 'const' declarations must be initialized for (v of []) { } ~ -!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. \ No newline at end of file +!!! error TS2540: Cannot assign to 'v' because it is a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/for-of3.errors.txt b/tests/baselines/reference/for-of3.errors.txt index 99ed3098a6389..1d58db6f186b7 100644 --- a/tests/baselines/reference/for-of3.errors.txt +++ b/tests/baselines/reference/for-of3.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/es6/for-ofStatements/for-of3.ts(2,6): error TS2487: Invalid left-hand side in 'for...of' statement. +tests/cases/conformance/es6/for-ofStatements/for-of3.ts(2,6): error TS2487: The left-hand side of a 'for...of' statement must be a variable or a property access. ==== tests/cases/conformance/es6/for-ofStatements/for-of3.ts (1 errors) ==== var v: any; for (v++ of []) { } ~~~ -!!! error TS2487: Invalid left-hand side in 'for...of' statement. \ No newline at end of file +!!! error TS2487: The left-hand side of a 'for...of' statement must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/importsImplicitlyReadonly.errors.txt b/tests/baselines/reference/importsImplicitlyReadonly.errors.txt index cc6e1918020e5..43596ffcea32e 100644 --- a/tests/baselines/reference/importsImplicitlyReadonly.errors.txt +++ b/tests/baselines/reference/importsImplicitlyReadonly.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/externalModules/b.ts(6,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/externalModules/b.ts(7,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/externalModules/b.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/externalModules/b.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/conformance/externalModules/b.ts(6,1): error TS2539: Cannot assign to 'x' because it is not a variable. +tests/cases/conformance/externalModules/b.ts(7,1): error TS2539: Cannot assign to 'y' because it is not a variable. +tests/cases/conformance/externalModules/b.ts(8,4): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/conformance/externalModules/b.ts(9,4): error TS2540: Cannot assign to 'y' because it is a constant or a read-only property. ==== tests/cases/conformance/externalModules/b.ts (4 errors) ==== @@ -12,16 +12,16 @@ tests/cases/conformance/externalModules/b.ts(9,1): error TS2450: Left-hand side x = 1; // Error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'x' because it is not a variable. y = 1; // Error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'y' because it is not a variable. a1.x = 1; // Error - ~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. a1.y = 1; // Error - ~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'y' because it is a constant or a read-only property. a2.x = 1; a2.y = 1; a3.x = 1; diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt index 4aae7f5b51ea4..0a303d12bf37a 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt @@ -1,36 +1,36 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(24,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(25,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(26,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(25,25): error TS2539: Cannot assign to 'A' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(26,25): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(27,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(28,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(30,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(31,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(32,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(31,23): error TS2539: Cannot assign to 'A' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(32,23): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(33,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(34,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(37,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(38,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(39,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(39,26): error TS2539: Cannot assign to 'undefined' because it is not a variable. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(41,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(42,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(43,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(46,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(47,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(48,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(43,24): error TS2539: Cannot assign to 'undefined' because it is not a variable. +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 TS2365: Operator '+' cannot be applied to types 'undefined' 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, property or indexer. +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 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, property or indexer. +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 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, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(55,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(56,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +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 TS2365: Operator '+' cannot be applied to types 'undefined' 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, property or indexer. +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 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, property or indexer. +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 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. @@ -74,10 +74,10 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. var ResultIsNumber2 = ++A; ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'A' because it is not a variable. var ResultIsNumber3 = ++M; ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. var ResultIsNumber4 = ++obj; ~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -90,10 +90,10 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. var ResultIsNumber7 = A++; ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'A' because it is not a variable. var ResultIsNumber8 = M++; ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. var ResultIsNumber9 = obj++; ~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -110,7 +110,7 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. var ResultIsNumber13 = ++undefined; ~~~~~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'undefined' because it is not a variable. var ResultIsNumber14 = null++; ~~~~ @@ -120,28 +120,28 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. var ResultIsNumber16 = undefined++; ~~~~~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'undefined' because it is not a variable. // any type expressions var ResultIsNumber17 = ++foo(); ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber18 = ++A.foo(); ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber19 = ++(null + undefined); ~~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber20 = ++(null + null); ~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~ !!! 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, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber22 = ++obj1.x; @@ -153,23 +153,23 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp var ResultIsNumber24 = foo()++; ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber25 = A.foo()++; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber26 = (null + undefined)++; ~~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber27 = (null + null)++; ~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~ !!! 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, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber29 = obj1.x++; diff --git a/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt b/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt index fc8b682b59e86..8fdbc34356216 100644 --- a/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt +++ b/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(6,25): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(7,23): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(10,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(12,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(6,31): error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(7,29): error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(10,9): error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(12,7): error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. ==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts (4 errors) ==== @@ -11,17 +11,17 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp // expression var ResultIsNumber1 = ++ENUM1["B"]; - ~~~~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. var ResultIsNumber2 = ENUM1.B++; - ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. // miss assignment operator ++ENUM1["B"]; - ~~~~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. ENUM1.B++; - ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. \ No newline at end of file + ~ +!!! error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/incrementOperatorWithEnumTypeInvalidOperations.errors.txt b/tests/baselines/reference/incrementOperatorWithEnumTypeInvalidOperations.errors.txt index 08a1b8ec460ea..ac021746157a0 100644 --- a/tests/baselines/reference/incrementOperatorWithEnumTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/incrementOperatorWithEnumTypeInvalidOperations.errors.txt @@ -1,13 +1,13 @@ -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(7,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(8,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(10,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(11,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(7,25): error TS2539: Cannot assign to 'ENUM' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(8,25): error TS2539: Cannot assign to 'ENUM1' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(10,23): error TS2539: Cannot assign to 'ENUM' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(11,23): error TS2539: Cannot assign to 'ENUM1' because it is not a variable. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(14,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(15,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(18,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(19,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(21,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(22,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(18,3): error TS2539: Cannot assign to 'ENUM' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(19,3): error TS2539: Cannot assign to 'ENUM1' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(21,1): error TS2539: Cannot assign to 'ENUM' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(22,1): error TS2539: Cannot assign to 'ENUM1' because it is not a variable. ==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts (10 errors) ==== @@ -19,17 +19,17 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp // enum type var var ResultIsNumber1 = ++ENUM; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM' because it is not a variable. var ResultIsNumber2 = ++ENUM1; ~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM1' because it is not a variable. var ResultIsNumber3 = ENUM++; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM' because it is not a variable. var ResultIsNumber4 = ENUM1++; ~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM1' because it is not a variable. // enum type expressions var ResultIsNumber5 = ++(ENUM[1] + ENUM[2]); @@ -42,14 +42,14 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp // miss assignment operator ++ENUM; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM' because it is not a variable. ++ENUM1; ~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM1' because it is not a variable. ENUM++; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM' because it is not a variable. ENUM1++; ~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. \ No newline at end of file +!!! error TS2539: Cannot assign to 'ENUM1' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/incrementOperatorWithNumberTypeInvalidOperations.errors.txt b/tests/baselines/reference/incrementOperatorWithNumberTypeInvalidOperations.errors.txt index 71c3ad67c4665..093a41aa35557 100644 --- a/tests/baselines/reference/incrementOperatorWithNumberTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/incrementOperatorWithNumberTypeInvalidOperations.errors.txt @@ -1,23 +1,23 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(18,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(19,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(22,25): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(22,25): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(23,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(24,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(26,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(26,23): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(27,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(28,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(31,25): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(32,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(33,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(35,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(36,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(37,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(40,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(31,25): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(32,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/incrementOperatorWithNumberTypeInvalidOperations.ts(33,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/incrementOperatorWithNumberTypeInvalidOperations.ts(35,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/incrementOperatorWithNumberTypeInvalidOperations.ts(36,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/incrementOperatorWithNumberTypeInvalidOperations.ts(37,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/incrementOperatorWithNumberTypeInvalidOperations.ts(40,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(41,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(42,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(44,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(42,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(44,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(45,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(46,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(46,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts (20 errors) ==== @@ -48,7 +48,7 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp // number type literal var ResultIsNumber3 = ++1; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber4 = ++{ x: 1, y: 2}; ~~~~~~~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -58,7 +58,7 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp var ResultIsNumber6 = 1++; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber7 = { x: 1, y: 2 }++; ~~~~~~~~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -69,41 +69,41 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp // number type expressions var ResultIsNumber9 = ++foo(); ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber10 = ++A.foo(); ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber11 = ++(NUMBER + NUMBER); ~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber12 = foo()++; ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber13 = A.foo()++; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber14 = (NUMBER + NUMBER)++; ~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. // miss assignment operator ++1; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ++NUMBER1; ~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. ++foo(); ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. 1++; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. NUMBER1++; ~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. foo()++; ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. \ No newline at end of file +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/indexTypeCheck.errors.txt b/tests/baselines/reference/indexTypeCheck.errors.txt index 06b844f8321d1..9d839e9eb3022 100644 --- a/tests/baselines/reference/indexTypeCheck.errors.txt +++ b/tests/baselines/reference/indexTypeCheck.errors.txt @@ -5,7 +5,7 @@ tests/cases/compiler/indexTypeCheck.ts(22,2): error TS2413: Numeric index type ' tests/cases/compiler/indexTypeCheck.ts(27,2): error TS2413: Numeric index type 'number' is not assignable to string index type 'string'. tests/cases/compiler/indexTypeCheck.ts(32,3): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/indexTypeCheck.ts(36,3): error TS1023: An index signature parameter type must be 'string' or 'number'. -tests/cases/compiler/indexTypeCheck.ts(51,1): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/compiler/indexTypeCheck.ts(51,8): error TS2538: Type 'Blue' cannot be used as an index type. ==== tests/cases/compiler/indexTypeCheck.ts (8 errors) ==== @@ -74,8 +74,8 @@ tests/cases/compiler/indexTypeCheck.ts(51,1): error TS2342: An index expression s[{}]; // ok yellow[blue]; // error - ~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~ +!!! error TS2538: Type 'Blue' cannot be used as an index type. var x:number[]; x[0]; diff --git a/tests/baselines/reference/indexWithUndefinedAndNull.errors.txt b/tests/baselines/reference/indexWithUndefinedAndNull.errors.txt new file mode 100644 index 0000000000000..6d6fa9c39e82c --- /dev/null +++ b/tests/baselines/reference/indexWithUndefinedAndNull.errors.txt @@ -0,0 +1,28 @@ +tests/cases/compiler/indexWithUndefinedAndNull.ts(9,21): error TS2538: Type 'undefined' cannot be used as an index type. +tests/cases/compiler/indexWithUndefinedAndNull.ts(10,9): error TS2538: Type 'null' cannot be used as an index type. +tests/cases/compiler/indexWithUndefinedAndNull.ts(11,21): error TS2538: Type 'undefined' cannot be used as an index type. +tests/cases/compiler/indexWithUndefinedAndNull.ts(12,9): error TS2538: Type 'null' cannot be used as an index type. + + +==== tests/cases/compiler/indexWithUndefinedAndNull.ts (4 errors) ==== + interface N { + [n: number]: string; + } + interface S { + [s: string]: number; + } + let n: N; + let s: S; + let str: string = n[undefined]; + ~~~~~~~~~ +!!! error TS2538: Type 'undefined' cannot be used as an index type. + str = n[null]; + ~~~~ +!!! error TS2538: Type 'null' cannot be used as an index type. + let num: number = s[undefined]; + ~~~~~~~~~ +!!! error TS2538: Type 'undefined' cannot be used as an index type. + num = s[null]; + ~~~~ +!!! error TS2538: Type 'null' cannot be used as an index type. + \ No newline at end of file diff --git a/tests/baselines/reference/indexWithUndefinedAndNullStrictNullChecks.errors.txt b/tests/baselines/reference/indexWithUndefinedAndNullStrictNullChecks.errors.txt index a1fce75c54e9c..764ce212971a7 100644 --- a/tests/baselines/reference/indexWithUndefinedAndNullStrictNullChecks.errors.txt +++ b/tests/baselines/reference/indexWithUndefinedAndNullStrictNullChecks.errors.txt @@ -1,11 +1,11 @@ tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(9,19): error TS2454: Variable 'n' is used before being assigned. -tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(9,19): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(9,21): error TS2538: Type 'undefined' cannot be used as an index type. tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(10,7): error TS2454: Variable 'n' is used before being assigned. -tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(10,7): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(10,9): error TS2538: Type 'null' cannot be used as an index type. tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(11,19): error TS2454: Variable 's' is used before being assigned. -tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(11,19): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(11,21): error TS2538: Type 'undefined' cannot be used as an index type. tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(12,7): error TS2454: Variable 's' is used before being assigned. -tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(12,7): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(12,9): error TS2538: Type 'null' cannot be used as an index type. ==== tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts (8 errors) ==== @@ -20,21 +20,21 @@ tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(12,7): error T let str: string = n[undefined]; ~ !!! error TS2454: Variable 'n' is used before being assigned. - ~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~~~~~~ +!!! error TS2538: Type 'undefined' cannot be used as an index type. str = n[null]; ~ !!! error TS2454: Variable 'n' is used before being assigned. - ~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~ +!!! error TS2538: Type 'null' cannot be used as an index type. let num: number = s[undefined]; ~ !!! error TS2454: Variable 's' is used before being assigned. - ~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~~~~~~ +!!! error TS2538: Type 'undefined' cannot be used as an index type. num = s[null]; ~ !!! error TS2454: Variable 's' is used before being assigned. - ~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~ +!!! error TS2538: Type 'null' cannot be used as an index type. \ No newline at end of file diff --git a/tests/baselines/reference/intersectionTypeReadonly.errors.txt b/tests/baselines/reference/intersectionTypeReadonly.errors.txt index d9e22fd222329..88ca9cb3b0c1b 100644 --- a/tests/baselines/reference/intersectionTypeReadonly.errors.txt +++ b/tests/baselines/reference/intersectionTypeReadonly.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(21,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(23,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(25,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(17,6): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. +tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(19,11): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. +tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(21,9): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. +tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(23,15): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. +tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(25,15): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. ==== tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts (5 errors) ==== @@ -23,22 +23,22 @@ tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(25,1): er } let base: Base; base.value = 12 // error, lhs can't be a readonly property - ~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. let identical: Base & Identical; identical.value = 12; // error, lhs can't be a readonly property - ~~~~~~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. let mutable: Base & Mutable; mutable.value = 12; // error, lhs can't be a readonly property - ~~~~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. let differentType: Base & DifferentType; differentType.value = 12; // error, lhs can't be a readonly property - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. let differentName: Base & DifferentName; differentName.value = 12; // error, property 'value' doesn't exist - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/invalidBooleanAssignments.errors.txt b/tests/baselines/reference/invalidBooleanAssignments.errors.txt index 7963197a0037d..06ec14b4dd6eb 100644 --- a/tests/baselines/reference/invalidBooleanAssignments.errors.txt +++ b/tests/baselines/reference/invalidBooleanAssignments.errors.txt @@ -5,9 +5,9 @@ tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(9, tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(12,5): error TS2322: Type 'true' is not assignable to type 'C'. tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(15,5): error TS2322: Type 'true' is not assignable to type 'I'. tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(17,5): error TS2322: Type 'true' is not assignable to type '() => string'. -tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(21,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(21,1): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(24,5): error TS2322: Type 'boolean' is not assignable to type 'T'. -tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(26,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(26,1): error TS2539: Cannot assign to 'i' because it is not a variable. ==== tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts (10 errors) ==== @@ -47,7 +47,7 @@ tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(26 module M { export var a = 1; } M = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. function i(a: T) { a = x; @@ -56,4 +56,4 @@ tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(26 } i = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2539: Cannot assign to 'i' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/invalidNumberAssignments.errors.txt b/tests/baselines/reference/invalidNumberAssignments.errors.txt index 23f308830ff12..102376f1c501e 100644 --- a/tests/baselines/reference/invalidNumberAssignments.errors.txt +++ b/tests/baselines/reference/invalidNumberAssignments.errors.txt @@ -5,9 +5,9 @@ tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(9,5) tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(12,5): error TS2322: Type 'number' is not assignable to type 'I'. tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(14,5): error TS2322: Type '1' is not assignable to type '{ baz: string; }'. tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(15,5): error TS2322: Type '1' is not assignable to type '{ 0: number; }'. -tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(18,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(18,1): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(21,5): error TS2322: Type 'number' is not assignable to type 'T'. -tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(23,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(23,1): error TS2539: Cannot assign to 'i' because it is not a variable. ==== tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts (10 errors) ==== @@ -44,7 +44,7 @@ tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(23,1 module M { export var x = 1; } M = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. function i(a: T) { a = x; @@ -53,4 +53,4 @@ tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(23,1 } i = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2539: Cannot assign to 'i' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/invalidStringAssignments.errors.txt b/tests/baselines/reference/invalidStringAssignments.errors.txt index b37c56e8a40b6..728ce09e6b41e 100644 --- a/tests/baselines/reference/invalidStringAssignments.errors.txt +++ b/tests/baselines/reference/invalidStringAssignments.errors.txt @@ -5,9 +5,9 @@ tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(9,5) tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(12,5): error TS2322: Type 'string' is not assignable to type 'I'. tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(14,5): error TS2322: Type '1' is not assignable to type '{ baz: string; }'. tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(15,5): error TS2322: Type '1' is not assignable to type '{ 0: number; }'. -tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(18,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(18,1): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(21,5): error TS2322: Type 'string' is not assignable to type 'T'. -tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(23,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(23,1): error TS2539: Cannot assign to 'i' because it is not a variable. tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(26,5): error TS2322: Type 'string' is not assignable to type 'E'. @@ -45,7 +45,7 @@ tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(26,5 module M { export var x = 1; } M = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. function i(a: T) { a = x; @@ -54,7 +54,7 @@ tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(26,5 } i = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'i' because it is not a variable. enum E { A } var j: E = x; diff --git a/tests/baselines/reference/invalidUndefinedAssignments.errors.txt b/tests/baselines/reference/invalidUndefinedAssignments.errors.txt index 05921e9433f52..b0a30f2dff3a9 100644 --- a/tests/baselines/reference/invalidUndefinedAssignments.errors.txt +++ b/tests/baselines/reference/invalidUndefinedAssignments.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(4,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(9,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(4,1): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(5,3): error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. +tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(9,1): error TS2539: Cannot assign to 'C' because it is not a variable. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(14,1): error TS2693: 'I' only refers to a type, but is being used as a value here. -tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(21,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(17,1): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(21,1): error TS2539: Cannot assign to 'i' because it is not a variable. ==== tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts (6 errors) ==== @@ -12,16 +12,16 @@ tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.t enum E { A } E = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'E' because it is not a variable. E.A = x; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. class C { foo: string } var f: C; C = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. interface I { foo: string } var g: I; @@ -33,10 +33,10 @@ tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.t module M { export var x = 1; } M = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. function i(a: T) { } // BUG 767030 i = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2539: Cannot assign to 'i' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/invalidVoidAssignments.errors.txt b/tests/baselines/reference/invalidVoidAssignments.errors.txt index de19fc3a21874..ae599fb52b0be 100644 --- a/tests/baselines/reference/invalidVoidAssignments.errors.txt +++ b/tests/baselines/reference/invalidVoidAssignments.errors.txt @@ -5,9 +5,9 @@ tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(9,5): er tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(12,5): error TS2322: Type 'void' is not assignable to type 'I'. tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(14,5): error TS2322: Type '1' is not assignable to type '{ baz: string; }'. tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(15,5): error TS2322: Type '1' is not assignable to type '{ 0: number; }'. -tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(18,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(18,1): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(21,5): error TS2322: Type 'void' is not assignable to type 'T'. -tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(23,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(23,1): error TS2539: Cannot assign to 'i' because it is not a variable. tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(26,1): error TS2322: Type 'typeof E' is not assignable to type 'void'. tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(27,1): error TS2322: Type 'E' is not assignable to type 'void'. tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(29,1): error TS2322: Type '{ f(): void; }' is not assignable to type 'void'. @@ -47,7 +47,7 @@ tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(29,1): e module M { export var x = 1; } M = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. function i(a: T) { a = x; @@ -56,7 +56,7 @@ tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(29,1): e } i = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'i' because it is not a variable. enum E { A } x = E; diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js new file mode 100644 index 0000000000000..5d986f3e89203 --- /dev/null +++ b/tests/baselines/reference/keyofAndIndexedAccess.js @@ -0,0 +1,350 @@ +//// [keyofAndIndexedAccess.ts] + +class Shape { + name: string; + width: number; + height: number; + visible: boolean; +} + +class Item { + name: string; + price: number; +} + +class Options { + visible: "yes" | "no"; +} + +type Dictionary = { [x: string]: T }; + +const enum E { A, B, C } + +type K00 = keyof any; // string | number +type K01 = keyof string; // number | "toString" | "charAt" | ... +type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ... +type K03 = keyof boolean; // "valueOf" +type K04 = keyof void; // never +type K05 = keyof undefined; // never +type K06 = keyof null; // never +type K07 = keyof never; // never + +type K10 = keyof Shape; // "name" | "width" | "height" | "visible" +type K11 = keyof Shape[]; // number | "length" | "toString" | ... +type K12 = keyof Dictionary; // string | number +type K13 = keyof {}; // never +type K14 = keyof Object; // "constructor" | "toString" | ... +type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ... +type K16 = keyof [string, number]; // number | "0" | "1" | "length" | "toString" | ... +type K17 = keyof (Shape | Item); // "name" +type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | "price" + +type KeyOf = keyof T; + +type K20 = KeyOf; // "name" | "width" | "height" | "visible" +type K21 = KeyOf>; // string | number + +type NAME = "name"; +type WIDTH_OR_HEIGHT = "width" | "height"; + +type Q10 = Shape["name"]; // string +type Q11 = Shape["width" | "height"]; // number +type Q12 = Shape["name" | "visible"]; // string | boolean + +type Q20 = Shape[NAME]; // string +type Q21 = Shape[WIDTH_OR_HEIGHT]; // number + +type Q30 = [string, number][0]; // string +type Q31 = [string, number][1]; // number +type Q32 = [string, number][2]; // string | number +type Q33 = [string, number][E.A]; // string +type Q34 = [string, number][E.B]; // number +type Q35 = [string, number][E.C]; // string | number +type Q36 = [string, number]["0"]; // string +type Q37 = [string, number]["1"]; // string + +type Q40 = (Shape | Options)["visible"]; // boolean | "yes" | "no" +type Q41 = (Shape & Options)["visible"]; // true & "yes" | true & "no" | false & "yes" | false & "no" + +type Q50 = Dictionary["howdy"]; // Shape +type Q51 = Dictionary[123]; // Shape +type Q52 = Dictionary[E.B]; // Shape + +declare let cond: boolean; + +function getProperty(obj: T, key: K) { + return obj[key]; +} + +function setProperty(obj: T, key: K, value: T[K]) { + obj[key] = value; +} + +function f10(shape: Shape) { + let name = getProperty(shape, "name"); // string + let widthOrHeight = getProperty(shape, cond ? "width" : "height"); // number + let nameOrVisible = getProperty(shape, cond ? "name" : "visible"); // string | boolean + setProperty(shape, "name", "rectangle"); + setProperty(shape, cond ? "width" : "height", 10); + setProperty(shape, cond ? "name" : "visible", true); // Technically not safe +} + +function f11(a: Shape[]) { + let len = getProperty(a, "length"); // number + let shape = getProperty(a, 1000); // Shape + setProperty(a, 1000, getProperty(a, 1001)); +} + +function f12(t: [Shape, boolean]) { + let len = getProperty(t, "length"); + let s1 = getProperty(t, 0); // Shape + let s2 = getProperty(t, "0"); // Shape + let b1 = getProperty(t, 1); // boolean + let b2 = getProperty(t, "1"); // boolean + let x1 = getProperty(t, 2); // Shape | boolean +} + +function f13(foo: any, bar: any) { + let x = getProperty(foo, "x"); // any + let y = getProperty(foo, 100); // any + let z = getProperty(foo, bar); // any +} + +class Component { + props: PropType; + getProperty(key: K) { + return this.props[key]; + } + setProperty(key: K, value: PropType[K]) { + this.props[key] = value; + } +} + +function f20(component: Component) { + let name = component.getProperty("name"); // string + let widthOrHeight = component.getProperty(cond ? "width" : "height"); // number + let nameOrVisible = component.getProperty(cond ? "name" : "visible"); // string | boolean + component.setProperty("name", "rectangle"); + component.setProperty(cond ? "width" : "height", 10) + component.setProperty(cond ? "name" : "visible", true); // Technically not safe +} + +function pluck(array: T[], key: K) { + return array.map(x => x[key]); +} + +function f30(shapes: Shape[]) { + let names = pluck(shapes, "name"); // string[] + let widths = pluck(shapes, "width"); // number[] + let nameOrVisibles = pluck(shapes, cond ? "name" : "visible"); // (string | boolean)[] +} + +function f31(key: K) { + const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; + return shape[key]; // Shape[K] +} + +function f32(key: K) { + const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; + return shape[key]; // Shape[K] +} + +class C { + public x: string; + protected y: string; + private z: string; +} + +// Indexed access expressions have always permitted access to private and protected members. +// For consistency we also permit such access in indexed access types. +function f40(c: C) { + type X = C["x"]; + type Y = C["y"]; + type Z = C["z"]; + let x: X = c["x"]; + let y: Y = c["y"]; + let z: Z = c["z"]; +} + +//// [keyofAndIndexedAccess.js] +var Shape = (function () { + function Shape() { + } + return Shape; +}()); +var Item = (function () { + function Item() { + } + return Item; +}()); +var Options = (function () { + function Options() { + } + return Options; +}()); +function getProperty(obj, key) { + return obj[key]; +} +function setProperty(obj, key, value) { + obj[key] = value; +} +function f10(shape) { + var name = getProperty(shape, "name"); // string + var widthOrHeight = getProperty(shape, cond ? "width" : "height"); // number + var nameOrVisible = getProperty(shape, cond ? "name" : "visible"); // string | boolean + setProperty(shape, "name", "rectangle"); + setProperty(shape, cond ? "width" : "height", 10); + setProperty(shape, cond ? "name" : "visible", true); // Technically not safe +} +function f11(a) { + var len = getProperty(a, "length"); // number + var shape = getProperty(a, 1000); // Shape + setProperty(a, 1000, getProperty(a, 1001)); +} +function f12(t) { + var len = getProperty(t, "length"); + var s1 = getProperty(t, 0); // Shape + var s2 = getProperty(t, "0"); // Shape + var b1 = getProperty(t, 1); // boolean + var b2 = getProperty(t, "1"); // boolean + var x1 = getProperty(t, 2); // Shape | boolean +} +function f13(foo, bar) { + var x = getProperty(foo, "x"); // any + var y = getProperty(foo, 100); // any + var z = getProperty(foo, bar); // any +} +var Component = (function () { + function Component() { + } + Component.prototype.getProperty = function (key) { + return this.props[key]; + }; + Component.prototype.setProperty = function (key, value) { + this.props[key] = value; + }; + return Component; +}()); +function f20(component) { + var name = component.getProperty("name"); // string + var widthOrHeight = component.getProperty(cond ? "width" : "height"); // number + var nameOrVisible = component.getProperty(cond ? "name" : "visible"); // string | boolean + component.setProperty("name", "rectangle"); + component.setProperty(cond ? "width" : "height", 10); + component.setProperty(cond ? "name" : "visible", true); // Technically not safe +} +function pluck(array, key) { + return array.map(function (x) { return x[key]; }); +} +function f30(shapes) { + var names = pluck(shapes, "name"); // string[] + var widths = pluck(shapes, "width"); // number[] + var nameOrVisibles = pluck(shapes, cond ? "name" : "visible"); // (string | boolean)[] +} +function f31(key) { + var shape = { name: "foo", width: 5, height: 10, visible: true }; + return shape[key]; // Shape[K] +} +function f32(key) { + var shape = { name: "foo", width: 5, height: 10, visible: true }; + return shape[key]; // Shape[K] +} +var C = (function () { + function C() { + } + return C; +}()); +// Indexed access expressions have always permitted access to private and protected members. +// For consistency we also permit such access in indexed access types. +function f40(c) { + var x = c["x"]; + var y = c["y"]; + var z = c["z"]; +} + + +//// [keyofAndIndexedAccess.d.ts] +declare class Shape { + name: string; + width: number; + height: number; + visible: boolean; +} +declare class Item { + name: string; + price: number; +} +declare class Options { + visible: "yes" | "no"; +} +declare type Dictionary = { + [x: string]: T; +}; +declare const enum E { + A = 0, + B = 1, + C = 2, +} +declare type K00 = keyof any; +declare type K01 = keyof string; +declare type K02 = keyof number; +declare type K03 = keyof boolean; +declare type K04 = keyof void; +declare type K05 = keyof undefined; +declare type K06 = keyof null; +declare type K07 = keyof never; +declare type K10 = keyof Shape; +declare type K11 = keyof Shape[]; +declare type K12 = keyof Dictionary; +declare type K13 = keyof {}; +declare type K14 = keyof Object; +declare type K15 = keyof E; +declare type K16 = keyof [string, number]; +declare type K17 = keyof (Shape | Item); +declare type K18 = keyof (Shape & Item); +declare type KeyOf = keyof T; +declare type K20 = KeyOf; +declare type K21 = KeyOf>; +declare type NAME = "name"; +declare type WIDTH_OR_HEIGHT = "width" | "height"; +declare type Q10 = Shape["name"]; +declare type Q11 = Shape["width" | "height"]; +declare type Q12 = Shape["name" | "visible"]; +declare type Q20 = Shape[NAME]; +declare type Q21 = Shape[WIDTH_OR_HEIGHT]; +declare type Q30 = [string, number][0]; +declare type Q31 = [string, number][1]; +declare type Q32 = [string, number][2]; +declare type Q33 = [string, number][E.A]; +declare type Q34 = [string, number][E.B]; +declare type Q35 = [string, number][E.C]; +declare type Q36 = [string, number]["0"]; +declare type Q37 = [string, number]["1"]; +declare type Q40 = (Shape | Options)["visible"]; +declare type Q41 = (Shape & Options)["visible"]; +declare type Q50 = Dictionary["howdy"]; +declare type Q51 = Dictionary[123]; +declare type Q52 = Dictionary[E.B]; +declare let cond: boolean; +declare function getProperty(obj: T, key: K): T[K]; +declare function setProperty(obj: T, key: K, value: T[K]): void; +declare function f10(shape: Shape): void; +declare function f11(a: Shape[]): void; +declare function f12(t: [Shape, boolean]): void; +declare function f13(foo: any, bar: any): void; +declare class Component { + props: PropType; + getProperty(key: K): PropType[K]; + setProperty(key: K, value: PropType[K]): void; +} +declare function f20(component: Component): void; +declare function pluck(array: T[], key: K): T[K][]; +declare function f30(shapes: Shape[]): void; +declare function f31(key: K): Shape[K]; +declare function f32(key: K): Shape[K]; +declare class C { + x: string; + protected y: string; + private z; +} +declare function f40(c: C): void; diff --git a/tests/baselines/reference/keyofAndIndexedAccess.symbols b/tests/baselines/reference/keyofAndIndexedAccess.symbols new file mode 100644 index 0000000000000..d3e967ed12504 --- /dev/null +++ b/tests/baselines/reference/keyofAndIndexedAccess.symbols @@ -0,0 +1,577 @@ +=== tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts === + +class Shape { +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + + name: string; +>name : Symbol(Shape.name, Decl(keyofAndIndexedAccess.ts, 1, 13)) + + width: number; +>width : Symbol(Shape.width, Decl(keyofAndIndexedAccess.ts, 2, 17)) + + height: number; +>height : Symbol(Shape.height, Decl(keyofAndIndexedAccess.ts, 3, 18)) + + visible: boolean; +>visible : Symbol(Shape.visible, Decl(keyofAndIndexedAccess.ts, 4, 19)) +} + +class Item { +>Item : Symbol(Item, Decl(keyofAndIndexedAccess.ts, 6, 1)) + + name: string; +>name : Symbol(Item.name, Decl(keyofAndIndexedAccess.ts, 8, 12)) + + price: number; +>price : Symbol(Item.price, Decl(keyofAndIndexedAccess.ts, 9, 17)) +} + +class Options { +>Options : Symbol(Options, Decl(keyofAndIndexedAccess.ts, 11, 1)) + + visible: "yes" | "no"; +>visible : Symbol(Options.visible, Decl(keyofAndIndexedAccess.ts, 13, 15)) +} + +type Dictionary = { [x: string]: T }; +>Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 15, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 17, 16)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 17, 24)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 17, 16)) + +const enum E { A, B, C } +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 17, 40)) +>A : Symbol(E.A, Decl(keyofAndIndexedAccess.ts, 19, 14)) +>B : Symbol(E.B, Decl(keyofAndIndexedAccess.ts, 19, 17)) +>C : Symbol(E.C, Decl(keyofAndIndexedAccess.ts, 19, 20)) + +type K00 = keyof any; // string | number +>K00 : Symbol(K00, Decl(keyofAndIndexedAccess.ts, 19, 24)) + +type K01 = keyof string; // number | "toString" | "charAt" | ... +>K01 : Symbol(K01, Decl(keyofAndIndexedAccess.ts, 21, 21)) + +type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ... +>K02 : Symbol(K02, Decl(keyofAndIndexedAccess.ts, 22, 24)) + +type K03 = keyof boolean; // "valueOf" +>K03 : Symbol(K03, Decl(keyofAndIndexedAccess.ts, 23, 24)) + +type K04 = keyof void; // never +>K04 : Symbol(K04, Decl(keyofAndIndexedAccess.ts, 24, 25)) + +type K05 = keyof undefined; // never +>K05 : Symbol(K05, Decl(keyofAndIndexedAccess.ts, 25, 22)) + +type K06 = keyof null; // never +>K06 : Symbol(K06, Decl(keyofAndIndexedAccess.ts, 26, 27)) + +type K07 = keyof never; // never +>K07 : Symbol(K07, Decl(keyofAndIndexedAccess.ts, 27, 22)) + +type K10 = keyof Shape; // "name" | "width" | "height" | "visible" +>K10 : Symbol(K10, Decl(keyofAndIndexedAccess.ts, 28, 23)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type K11 = keyof Shape[]; // number | "length" | "toString" | ... +>K11 : Symbol(K11, Decl(keyofAndIndexedAccess.ts, 30, 23)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type K12 = keyof Dictionary; // string | number +>K12 : Symbol(K12, Decl(keyofAndIndexedAccess.ts, 31, 25)) +>Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 15, 1)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type K13 = keyof {}; // never +>K13 : Symbol(K13, Decl(keyofAndIndexedAccess.ts, 32, 35)) + +type K14 = keyof Object; // "constructor" | "toString" | ... +>K14 : Symbol(K14, Decl(keyofAndIndexedAccess.ts, 33, 20)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ... +>K15 : Symbol(K15, Decl(keyofAndIndexedAccess.ts, 34, 24)) +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 17, 40)) + +type K16 = keyof [string, number]; // number | "0" | "1" | "length" | "toString" | ... +>K16 : Symbol(K16, Decl(keyofAndIndexedAccess.ts, 35, 19)) + +type K17 = keyof (Shape | Item); // "name" +>K17 : Symbol(K17, Decl(keyofAndIndexedAccess.ts, 36, 34)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>Item : Symbol(Item, Decl(keyofAndIndexedAccess.ts, 6, 1)) + +type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | "price" +>K18 : Symbol(K18, Decl(keyofAndIndexedAccess.ts, 37, 32)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>Item : Symbol(Item, Decl(keyofAndIndexedAccess.ts, 6, 1)) + +type KeyOf = keyof T; +>KeyOf : Symbol(KeyOf, Decl(keyofAndIndexedAccess.ts, 38, 32)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 40, 11)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 40, 11)) + +type K20 = KeyOf; // "name" | "width" | "height" | "visible" +>K20 : Symbol(K20, Decl(keyofAndIndexedAccess.ts, 40, 24)) +>KeyOf : Symbol(KeyOf, Decl(keyofAndIndexedAccess.ts, 38, 32)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type K21 = KeyOf>; // string | number +>K21 : Symbol(K21, Decl(keyofAndIndexedAccess.ts, 42, 24)) +>KeyOf : Symbol(KeyOf, Decl(keyofAndIndexedAccess.ts, 38, 32)) +>Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 15, 1)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type NAME = "name"; +>NAME : Symbol(NAME, Decl(keyofAndIndexedAccess.ts, 43, 36)) + +type WIDTH_OR_HEIGHT = "width" | "height"; +>WIDTH_OR_HEIGHT : Symbol(WIDTH_OR_HEIGHT, Decl(keyofAndIndexedAccess.ts, 45, 19)) + +type Q10 = Shape["name"]; // string +>Q10 : Symbol(Q10, Decl(keyofAndIndexedAccess.ts, 46, 42)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type Q11 = Shape["width" | "height"]; // number +>Q11 : Symbol(Q11, Decl(keyofAndIndexedAccess.ts, 48, 25)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type Q12 = Shape["name" | "visible"]; // string | boolean +>Q12 : Symbol(Q12, Decl(keyofAndIndexedAccess.ts, 49, 37)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type Q20 = Shape[NAME]; // string +>Q20 : Symbol(Q20, Decl(keyofAndIndexedAccess.ts, 50, 37)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>NAME : Symbol(NAME, Decl(keyofAndIndexedAccess.ts, 43, 36)) + +type Q21 = Shape[WIDTH_OR_HEIGHT]; // number +>Q21 : Symbol(Q21, Decl(keyofAndIndexedAccess.ts, 52, 23)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>WIDTH_OR_HEIGHT : Symbol(WIDTH_OR_HEIGHT, Decl(keyofAndIndexedAccess.ts, 45, 19)) + +type Q30 = [string, number][0]; // string +>Q30 : Symbol(Q30, Decl(keyofAndIndexedAccess.ts, 53, 34)) + +type Q31 = [string, number][1]; // number +>Q31 : Symbol(Q31, Decl(keyofAndIndexedAccess.ts, 55, 31)) + +type Q32 = [string, number][2]; // string | number +>Q32 : Symbol(Q32, Decl(keyofAndIndexedAccess.ts, 56, 31)) + +type Q33 = [string, number][E.A]; // string +>Q33 : Symbol(Q33, Decl(keyofAndIndexedAccess.ts, 57, 31)) +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 17, 40)) +>A : Symbol(E.A, Decl(keyofAndIndexedAccess.ts, 19, 14)) + +type Q34 = [string, number][E.B]; // number +>Q34 : Symbol(Q34, Decl(keyofAndIndexedAccess.ts, 58, 33)) +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 17, 40)) +>B : Symbol(E.B, Decl(keyofAndIndexedAccess.ts, 19, 17)) + +type Q35 = [string, number][E.C]; // string | number +>Q35 : Symbol(Q35, Decl(keyofAndIndexedAccess.ts, 59, 33)) +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 17, 40)) +>C : Symbol(E.C, Decl(keyofAndIndexedAccess.ts, 19, 20)) + +type Q36 = [string, number]["0"]; // string +>Q36 : Symbol(Q36, Decl(keyofAndIndexedAccess.ts, 60, 33)) + +type Q37 = [string, number]["1"]; // string +>Q37 : Symbol(Q37, Decl(keyofAndIndexedAccess.ts, 61, 33)) + +type Q40 = (Shape | Options)["visible"]; // boolean | "yes" | "no" +>Q40 : Symbol(Q40, Decl(keyofAndIndexedAccess.ts, 62, 33)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>Options : Symbol(Options, Decl(keyofAndIndexedAccess.ts, 11, 1)) + +type Q41 = (Shape & Options)["visible"]; // true & "yes" | true & "no" | false & "yes" | false & "no" +>Q41 : Symbol(Q41, Decl(keyofAndIndexedAccess.ts, 64, 40)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>Options : Symbol(Options, Decl(keyofAndIndexedAccess.ts, 11, 1)) + +type Q50 = Dictionary["howdy"]; // Shape +>Q50 : Symbol(Q50, Decl(keyofAndIndexedAccess.ts, 65, 40)) +>Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 15, 1)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type Q51 = Dictionary[123]; // Shape +>Q51 : Symbol(Q51, Decl(keyofAndIndexedAccess.ts, 67, 38)) +>Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 15, 1)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type Q52 = Dictionary[E.B]; // Shape +>Q52 : Symbol(Q52, Decl(keyofAndIndexedAccess.ts, 68, 34)) +>Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 15, 1)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 17, 40)) +>B : Symbol(E.B, Decl(keyofAndIndexedAccess.ts, 19, 17)) + +declare let cond: boolean; +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 71, 11)) + +function getProperty(obj: T, key: K) { +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 71, 26)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 73, 21)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 73, 23)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 73, 21)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 73, 43)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 73, 21)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 73, 50)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 73, 23)) + + return obj[key]; +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 73, 43)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 73, 50)) +} + +function setProperty(obj: T, key: K, value: T[K]) { +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 75, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 77, 21)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 77, 23)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 77, 21)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 77, 43)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 77, 21)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 77, 50)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 77, 23)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 77, 58)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 77, 21)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 77, 23)) + + obj[key] = value; +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 77, 43)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 77, 50)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 77, 58)) +} + +function f10(shape: Shape) { +>f10 : Symbol(f10, Decl(keyofAndIndexedAccess.ts, 79, 1)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 81, 13)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + + let name = getProperty(shape, "name"); // string +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 82, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 71, 26)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 81, 13)) + + let widthOrHeight = getProperty(shape, cond ? "width" : "height"); // number +>widthOrHeight : Symbol(widthOrHeight, Decl(keyofAndIndexedAccess.ts, 83, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 71, 26)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 81, 13)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 71, 11)) + + let nameOrVisible = getProperty(shape, cond ? "name" : "visible"); // string | boolean +>nameOrVisible : Symbol(nameOrVisible, Decl(keyofAndIndexedAccess.ts, 84, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 71, 26)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 81, 13)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 71, 11)) + + setProperty(shape, "name", "rectangle"); +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 75, 1)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 81, 13)) + + setProperty(shape, cond ? "width" : "height", 10); +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 75, 1)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 81, 13)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 71, 11)) + + setProperty(shape, cond ? "name" : "visible", true); // Technically not safe +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 75, 1)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 81, 13)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 71, 11)) +} + +function f11(a: Shape[]) { +>f11 : Symbol(f11, Decl(keyofAndIndexedAccess.ts, 88, 1)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 90, 13)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + + let len = getProperty(a, "length"); // number +>len : Symbol(len, Decl(keyofAndIndexedAccess.ts, 91, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 71, 26)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 90, 13)) + + let shape = getProperty(a, 1000); // Shape +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 92, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 71, 26)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 90, 13)) + + setProperty(a, 1000, getProperty(a, 1001)); +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 75, 1)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 90, 13)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 71, 26)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 90, 13)) +} + +function f12(t: [Shape, boolean]) { +>f12 : Symbol(f12, Decl(keyofAndIndexedAccess.ts, 94, 1)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 96, 13)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + + let len = getProperty(t, "length"); +>len : Symbol(len, Decl(keyofAndIndexedAccess.ts, 97, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 71, 26)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 96, 13)) + + let s1 = getProperty(t, 0); // Shape +>s1 : Symbol(s1, Decl(keyofAndIndexedAccess.ts, 98, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 71, 26)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 96, 13)) + + let s2 = getProperty(t, "0"); // Shape +>s2 : Symbol(s2, Decl(keyofAndIndexedAccess.ts, 99, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 71, 26)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 96, 13)) + + let b1 = getProperty(t, 1); // boolean +>b1 : Symbol(b1, Decl(keyofAndIndexedAccess.ts, 100, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 71, 26)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 96, 13)) + + let b2 = getProperty(t, "1"); // boolean +>b2 : Symbol(b2, Decl(keyofAndIndexedAccess.ts, 101, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 71, 26)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 96, 13)) + + let x1 = getProperty(t, 2); // Shape | boolean +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 102, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 71, 26)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 96, 13)) +} + +function f13(foo: any, bar: any) { +>f13 : Symbol(f13, Decl(keyofAndIndexedAccess.ts, 103, 1)) +>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 105, 13)) +>bar : Symbol(bar, Decl(keyofAndIndexedAccess.ts, 105, 22)) + + let x = getProperty(foo, "x"); // any +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 106, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 71, 26)) +>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 105, 13)) + + let y = getProperty(foo, 100); // any +>y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 107, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 71, 26)) +>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 105, 13)) + + let z = getProperty(foo, bar); // any +>z : Symbol(z, Decl(keyofAndIndexedAccess.ts, 108, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 71, 26)) +>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 105, 13)) +>bar : Symbol(bar, Decl(keyofAndIndexedAccess.ts, 105, 22)) +} + +class Component { +>Component : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 109, 1)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 111, 16)) + + props: PropType; +>props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 111, 27)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 111, 16)) + + getProperty(key: K) { +>getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 113, 16)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 111, 16)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 113, 42)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 113, 16)) + + return this.props[key]; +>this.props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 111, 27)) +>this : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 109, 1)) +>props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 111, 27)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 113, 42)) + } + setProperty(key: K, value: PropType[K]) { +>setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 116, 16)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 111, 16)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 116, 42)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 116, 16)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 116, 49)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 111, 16)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 116, 16)) + + this.props[key] = value; +>this.props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 111, 27)) +>this : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 109, 1)) +>props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 111, 27)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 116, 42)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 116, 49)) + } +} + +function f20(component: Component) { +>f20 : Symbol(f20, Decl(keyofAndIndexedAccess.ts, 119, 1)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) +>Component : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 109, 1)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + + let name = component.getProperty("name"); // string +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 122, 7)) +>component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) +>getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) + + let widthOrHeight = component.getProperty(cond ? "width" : "height"); // number +>widthOrHeight : Symbol(widthOrHeight, Decl(keyofAndIndexedAccess.ts, 123, 7)) +>component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) +>getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 71, 11)) + + let nameOrVisible = component.getProperty(cond ? "name" : "visible"); // string | boolean +>nameOrVisible : Symbol(nameOrVisible, Decl(keyofAndIndexedAccess.ts, 124, 7)) +>component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) +>getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 71, 11)) + + component.setProperty("name", "rectangle"); +>component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) +>setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) + + component.setProperty(cond ? "width" : "height", 10) +>component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) +>setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 71, 11)) + + component.setProperty(cond ? "name" : "visible", true); // Technically not safe +>component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) +>setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 71, 11)) +} + +function pluck(array: T[], key: K) { +>pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 128, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 130, 15)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 130, 17)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 130, 15)) +>array : Symbol(array, Decl(keyofAndIndexedAccess.ts, 130, 37)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 130, 15)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 130, 48)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 130, 17)) + + return array.map(x => x[key]); +>array.map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>array : Symbol(array, Decl(keyofAndIndexedAccess.ts, 130, 37)) +>map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 131, 21)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 131, 21)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 130, 48)) +} + +function f30(shapes: Shape[]) { +>f30 : Symbol(f30, Decl(keyofAndIndexedAccess.ts, 132, 1)) +>shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 134, 13)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + + let names = pluck(shapes, "name"); // string[] +>names : Symbol(names, Decl(keyofAndIndexedAccess.ts, 135, 7)) +>pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 128, 1)) +>shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 134, 13)) + + let widths = pluck(shapes, "width"); // number[] +>widths : Symbol(widths, Decl(keyofAndIndexedAccess.ts, 136, 7)) +>pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 128, 1)) +>shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 134, 13)) + + let nameOrVisibles = pluck(shapes, cond ? "name" : "visible"); // (string | boolean)[] +>nameOrVisibles : Symbol(nameOrVisibles, Decl(keyofAndIndexedAccess.ts, 137, 7)) +>pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 128, 1)) +>shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 134, 13)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 71, 11)) +} + +function f31(key: K) { +>f31 : Symbol(f31, Decl(keyofAndIndexedAccess.ts, 138, 1)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 140, 13)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 140, 36)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 140, 13)) + + const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 141, 9)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 141, 26)) +>width : Symbol(width, Decl(keyofAndIndexedAccess.ts, 141, 39)) +>height : Symbol(height, Decl(keyofAndIndexedAccess.ts, 141, 49)) +>visible : Symbol(visible, Decl(keyofAndIndexedAccess.ts, 141, 61)) + + return shape[key]; // Shape[K] +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 141, 9)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 140, 36)) +} + +function f32(key: K) { +>f32 : Symbol(f32, Decl(keyofAndIndexedAccess.ts, 143, 1)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 145, 13)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 145, 43)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 145, 13)) + + const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 146, 9)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 146, 26)) +>width : Symbol(width, Decl(keyofAndIndexedAccess.ts, 146, 39)) +>height : Symbol(height, Decl(keyofAndIndexedAccess.ts, 146, 49)) +>visible : Symbol(visible, Decl(keyofAndIndexedAccess.ts, 146, 61)) + + return shape[key]; // Shape[K] +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 146, 9)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 145, 43)) +} + +class C { +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 148, 1)) + + public x: string; +>x : Symbol(C.x, Decl(keyofAndIndexedAccess.ts, 150, 9)) + + protected y: string; +>y : Symbol(C.y, Decl(keyofAndIndexedAccess.ts, 151, 21)) + + private z: string; +>z : Symbol(C.z, Decl(keyofAndIndexedAccess.ts, 152, 24)) +} + +// Indexed access expressions have always permitted access to private and protected members. +// For consistency we also permit such access in indexed access types. +function f40(c: C) { +>f40 : Symbol(f40, Decl(keyofAndIndexedAccess.ts, 154, 1)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 158, 13)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 148, 1)) + + type X = C["x"]; +>X : Symbol(X, Decl(keyofAndIndexedAccess.ts, 158, 20)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 148, 1)) + + type Y = C["y"]; +>Y : Symbol(Y, Decl(keyofAndIndexedAccess.ts, 159, 20)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 148, 1)) + + type Z = C["z"]; +>Z : Symbol(Z, Decl(keyofAndIndexedAccess.ts, 160, 20)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 148, 1)) + + let x: X = c["x"]; +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 162, 7)) +>X : Symbol(X, Decl(keyofAndIndexedAccess.ts, 158, 20)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 158, 13)) +>"x" : Symbol(C.x, Decl(keyofAndIndexedAccess.ts, 150, 9)) + + let y: Y = c["y"]; +>y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 163, 7)) +>Y : Symbol(Y, Decl(keyofAndIndexedAccess.ts, 159, 20)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 158, 13)) +>"y" : Symbol(C.y, Decl(keyofAndIndexedAccess.ts, 151, 21)) + + let z: Z = c["z"]; +>z : Symbol(z, Decl(keyofAndIndexedAccess.ts, 164, 7)) +>Z : Symbol(Z, Decl(keyofAndIndexedAccess.ts, 160, 20)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 158, 13)) +>"z" : Symbol(C.z, Decl(keyofAndIndexedAccess.ts, 152, 24)) +} diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types new file mode 100644 index 0000000000000..74c06a2535da7 --- /dev/null +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -0,0 +1,681 @@ +=== tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts === + +class Shape { +>Shape : Shape + + name: string; +>name : string + + width: number; +>width : number + + height: number; +>height : number + + visible: boolean; +>visible : boolean +} + +class Item { +>Item : Item + + name: string; +>name : string + + price: number; +>price : number +} + +class Options { +>Options : Options + + visible: "yes" | "no"; +>visible : "yes" | "no" +} + +type Dictionary = { [x: string]: T }; +>Dictionary : { [x: string]: T; } +>T : T +>x : string +>T : T + +const enum E { A, B, C } +>E : E +>A : E.A +>B : E.B +>C : E.C + +type K00 = keyof any; // string | number +>K00 : string | number + +type K01 = keyof string; // number | "toString" | "charAt" | ... +>K01 : number | "length" | "toString" | "concat" | "slice" | "indexOf" | "lastIndexOf" | "charAt" | "charCodeAt" | "localeCompare" | "match" | "replace" | "search" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" | "valueOf" + +type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ... +>K02 : "toString" | "toLocaleString" | "valueOf" | "toFixed" | "toExponential" | "toPrecision" + +type K03 = keyof boolean; // "valueOf" +>K03 : "valueOf" + +type K04 = keyof void; // never +>K04 : never + +type K05 = keyof undefined; // never +>K05 : never + +type K06 = keyof null; // never +>K06 : never +>null : null + +type K07 = keyof never; // never +>K07 : never + +type K10 = keyof Shape; // "name" | "width" | "height" | "visible" +>K10 : "name" | "width" | "height" | "visible" +>Shape : Shape + +type K11 = keyof Shape[]; // number | "length" | "toString" | ... +>K11 : number | "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" +>Shape : Shape + +type K12 = keyof Dictionary; // string | number +>K12 : string | number +>Dictionary : { [x: string]: T; } +>Shape : Shape + +type K13 = keyof {}; // never +>K13 : never + +type K14 = keyof Object; // "constructor" | "toString" | ... +>K14 : "toString" | "toLocaleString" | "valueOf" | "constructor" | "hasOwnProperty" | "isPrototypeOf" | "propertyIsEnumerable" +>Object : Object + +type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ... +>K15 : "toString" | "toLocaleString" | "valueOf" | "toFixed" | "toExponential" | "toPrecision" +>E : E + +type K16 = keyof [string, number]; // number | "0" | "1" | "length" | "toString" | ... +>K16 : number | "0" | "1" | "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" + +type K17 = keyof (Shape | Item); // "name" +>K17 : "name" +>Shape : Shape +>Item : Item + +type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | "price" +>K18 : "name" | "width" | "height" | "visible" | "price" +>Shape : Shape +>Item : Item + +type KeyOf = keyof T; +>KeyOf : keyof T +>T : T +>T : T + +type K20 = KeyOf; // "name" | "width" | "height" | "visible" +>K20 : "name" | "width" | "height" | "visible" +>KeyOf : keyof T +>Shape : Shape + +type K21 = KeyOf>; // string | number +>K21 : string | number +>KeyOf : keyof T +>Dictionary : { [x: string]: T; } +>Shape : Shape + +type NAME = "name"; +>NAME : "name" + +type WIDTH_OR_HEIGHT = "width" | "height"; +>WIDTH_OR_HEIGHT : "width" | "height" + +type Q10 = Shape["name"]; // string +>Q10 : string +>Shape : Shape + +type Q11 = Shape["width" | "height"]; // number +>Q11 : number +>Shape : Shape + +type Q12 = Shape["name" | "visible"]; // string | boolean +>Q12 : string | boolean +>Shape : Shape + +type Q20 = Shape[NAME]; // string +>Q20 : string +>Shape : Shape +>NAME : "name" + +type Q21 = Shape[WIDTH_OR_HEIGHT]; // number +>Q21 : number +>Shape : Shape +>WIDTH_OR_HEIGHT : "width" | "height" + +type Q30 = [string, number][0]; // string +>Q30 : string + +type Q31 = [string, number][1]; // number +>Q31 : number + +type Q32 = [string, number][2]; // string | number +>Q32 : string | number + +type Q33 = [string, number][E.A]; // string +>Q33 : string +>E : any +>A : E.A + +type Q34 = [string, number][E.B]; // number +>Q34 : number +>E : any +>B : E.B + +type Q35 = [string, number][E.C]; // string | number +>Q35 : string | number +>E : any +>C : E.C + +type Q36 = [string, number]["0"]; // string +>Q36 : string + +type Q37 = [string, number]["1"]; // string +>Q37 : number + +type Q40 = (Shape | Options)["visible"]; // boolean | "yes" | "no" +>Q40 : boolean | "yes" | "no" +>Shape : Shape +>Options : Options + +type Q41 = (Shape & Options)["visible"]; // true & "yes" | true & "no" | false & "yes" | false & "no" +>Q41 : (true & "yes") | (true & "no") | (false & "yes") | (false & "no") +>Shape : Shape +>Options : Options + +type Q50 = Dictionary["howdy"]; // Shape +>Q50 : Shape +>Dictionary : { [x: string]: T; } +>Shape : Shape + +type Q51 = Dictionary[123]; // Shape +>Q51 : Shape +>Dictionary : { [x: string]: T; } +>Shape : Shape + +type Q52 = Dictionary[E.B]; // Shape +>Q52 : Shape +>Dictionary : { [x: string]: T; } +>Shape : Shape +>E : any +>B : E.B + +declare let cond: boolean; +>cond : boolean + +function getProperty(obj: T, key: K) { +>getProperty : (obj: T, key: K) => T[K] +>T : T +>K : K +>T : T +>obj : T +>T : T +>key : K +>K : K + + return obj[key]; +>obj[key] : T[K] +>obj : T +>key : K +} + +function setProperty(obj: T, key: K, value: T[K]) { +>setProperty : (obj: T, key: K, value: T[K]) => void +>T : T +>K : K +>T : T +>obj : T +>T : T +>key : K +>K : K +>value : T[K] +>T : T +>K : K + + obj[key] = value; +>obj[key] = value : T[K] +>obj[key] : T[K] +>obj : T +>key : K +>value : T[K] +} + +function f10(shape: Shape) { +>f10 : (shape: Shape) => void +>shape : Shape +>Shape : Shape + + let name = getProperty(shape, "name"); // string +>name : string +>getProperty(shape, "name") : string +>getProperty : (obj: T, key: K) => T[K] +>shape : Shape +>"name" : "name" + + let widthOrHeight = getProperty(shape, cond ? "width" : "height"); // number +>widthOrHeight : number +>getProperty(shape, cond ? "width" : "height") : number +>getProperty : (obj: T, key: K) => T[K] +>shape : Shape +>cond ? "width" : "height" : "width" | "height" +>cond : boolean +>"width" : "width" +>"height" : "height" + + let nameOrVisible = getProperty(shape, cond ? "name" : "visible"); // string | boolean +>nameOrVisible : string | boolean +>getProperty(shape, cond ? "name" : "visible") : string | boolean +>getProperty : (obj: T, key: K) => T[K] +>shape : Shape +>cond ? "name" : "visible" : "name" | "visible" +>cond : boolean +>"name" : "name" +>"visible" : "visible" + + setProperty(shape, "name", "rectangle"); +>setProperty(shape, "name", "rectangle") : void +>setProperty : (obj: T, key: K, value: T[K]) => void +>shape : Shape +>"name" : "name" +>"rectangle" : "rectangle" + + setProperty(shape, cond ? "width" : "height", 10); +>setProperty(shape, cond ? "width" : "height", 10) : void +>setProperty : (obj: T, key: K, value: T[K]) => void +>shape : Shape +>cond ? "width" : "height" : "width" | "height" +>cond : boolean +>"width" : "width" +>"height" : "height" +>10 : 10 + + setProperty(shape, cond ? "name" : "visible", true); // Technically not safe +>setProperty(shape, cond ? "name" : "visible", true) : void +>setProperty : (obj: T, key: K, value: T[K]) => void +>shape : Shape +>cond ? "name" : "visible" : "name" | "visible" +>cond : boolean +>"name" : "name" +>"visible" : "visible" +>true : true +} + +function f11(a: Shape[]) { +>f11 : (a: Shape[]) => void +>a : Shape[] +>Shape : Shape + + let len = getProperty(a, "length"); // number +>len : number +>getProperty(a, "length") : number +>getProperty : (obj: T, key: K) => T[K] +>a : Shape[] +>"length" : "length" + + let shape = getProperty(a, 1000); // Shape +>shape : Shape +>getProperty(a, 1000) : Shape +>getProperty : (obj: T, key: K) => T[K] +>a : Shape[] +>1000 : 1000 + + setProperty(a, 1000, getProperty(a, 1001)); +>setProperty(a, 1000, getProperty(a, 1001)) : void +>setProperty : (obj: T, key: K, value: T[K]) => void +>a : Shape[] +>1000 : 1000 +>getProperty(a, 1001) : Shape +>getProperty : (obj: T, key: K) => T[K] +>a : Shape[] +>1001 : 1001 +} + +function f12(t: [Shape, boolean]) { +>f12 : (t: [Shape, boolean]) => void +>t : [Shape, boolean] +>Shape : Shape + + let len = getProperty(t, "length"); +>len : number +>getProperty(t, "length") : number +>getProperty : (obj: T, key: K) => T[K] +>t : [Shape, boolean] +>"length" : "length" + + let s1 = getProperty(t, 0); // Shape +>s1 : Shape +>getProperty(t, 0) : Shape +>getProperty : (obj: T, key: K) => T[K] +>t : [Shape, boolean] +>0 : 0 + + let s2 = getProperty(t, "0"); // Shape +>s2 : Shape +>getProperty(t, "0") : Shape +>getProperty : (obj: T, key: K) => T[K] +>t : [Shape, boolean] +>"0" : "0" + + let b1 = getProperty(t, 1); // boolean +>b1 : boolean +>getProperty(t, 1) : boolean +>getProperty : (obj: T, key: K) => T[K] +>t : [Shape, boolean] +>1 : 1 + + let b2 = getProperty(t, "1"); // boolean +>b2 : boolean +>getProperty(t, "1") : boolean +>getProperty : (obj: T, key: K) => T[K] +>t : [Shape, boolean] +>"1" : "1" + + let x1 = getProperty(t, 2); // Shape | boolean +>x1 : boolean | Shape +>getProperty(t, 2) : boolean | Shape +>getProperty : (obj: T, key: K) => T[K] +>t : [Shape, boolean] +>2 : 2 +} + +function f13(foo: any, bar: any) { +>f13 : (foo: any, bar: any) => void +>foo : any +>bar : any + + let x = getProperty(foo, "x"); // any +>x : any +>getProperty(foo, "x") : any +>getProperty : (obj: T, key: K) => T[K] +>foo : any +>"x" : "x" + + let y = getProperty(foo, 100); // any +>y : any +>getProperty(foo, 100) : any +>getProperty : (obj: T, key: K) => T[K] +>foo : any +>100 : 100 + + let z = getProperty(foo, bar); // any +>z : any +>getProperty(foo, bar) : any +>getProperty : (obj: T, key: K) => T[K] +>foo : any +>bar : any +} + +class Component { +>Component : Component +>PropType : PropType + + props: PropType; +>props : PropType +>PropType : PropType + + getProperty(key: K) { +>getProperty : (key: K) => PropType[K] +>K : K +>PropType : PropType +>key : K +>K : K + + return this.props[key]; +>this.props[key] : PropType[K] +>this.props : PropType +>this : this +>props : PropType +>key : K + } + setProperty(key: K, value: PropType[K]) { +>setProperty : (key: K, value: PropType[K]) => void +>K : K +>PropType : PropType +>key : K +>K : K +>value : PropType[K] +>PropType : PropType +>K : K + + this.props[key] = value; +>this.props[key] = value : PropType[K] +>this.props[key] : PropType[K] +>this.props : PropType +>this : this +>props : PropType +>key : K +>value : PropType[K] + } +} + +function f20(component: Component) { +>f20 : (component: Component) => void +>component : Component +>Component : Component +>Shape : Shape + + let name = component.getProperty("name"); // string +>name : string +>component.getProperty("name") : string +>component.getProperty : (key: K) => Shape[K] +>component : Component +>getProperty : (key: K) => Shape[K] +>"name" : "name" + + let widthOrHeight = component.getProperty(cond ? "width" : "height"); // number +>widthOrHeight : number +>component.getProperty(cond ? "width" : "height") : number +>component.getProperty : (key: K) => Shape[K] +>component : Component +>getProperty : (key: K) => Shape[K] +>cond ? "width" : "height" : "width" | "height" +>cond : boolean +>"width" : "width" +>"height" : "height" + + let nameOrVisible = component.getProperty(cond ? "name" : "visible"); // string | boolean +>nameOrVisible : string | boolean +>component.getProperty(cond ? "name" : "visible") : string | boolean +>component.getProperty : (key: K) => Shape[K] +>component : Component +>getProperty : (key: K) => Shape[K] +>cond ? "name" : "visible" : "name" | "visible" +>cond : boolean +>"name" : "name" +>"visible" : "visible" + + component.setProperty("name", "rectangle"); +>component.setProperty("name", "rectangle") : void +>component.setProperty : (key: K, value: Shape[K]) => void +>component : Component +>setProperty : (key: K, value: Shape[K]) => void +>"name" : "name" +>"rectangle" : "rectangle" + + component.setProperty(cond ? "width" : "height", 10) +>component.setProperty(cond ? "width" : "height", 10) : void +>component.setProperty : (key: K, value: Shape[K]) => void +>component : Component +>setProperty : (key: K, value: Shape[K]) => void +>cond ? "width" : "height" : "width" | "height" +>cond : boolean +>"width" : "width" +>"height" : "height" +>10 : 10 + + component.setProperty(cond ? "name" : "visible", true); // Technically not safe +>component.setProperty(cond ? "name" : "visible", true) : void +>component.setProperty : (key: K, value: Shape[K]) => void +>component : Component +>setProperty : (key: K, value: Shape[K]) => void +>cond ? "name" : "visible" : "name" | "visible" +>cond : boolean +>"name" : "name" +>"visible" : "visible" +>true : true +} + +function pluck(array: T[], key: K) { +>pluck : (array: T[], key: K) => T[K][] +>T : T +>K : K +>T : T +>array : T[] +>T : T +>key : K +>K : K + + return array.map(x => x[key]); +>array.map(x => x[key]) : T[K][] +>array.map : { (this: [T, T, T, T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U, U, U, U]; (this: [T, T, T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U, U, U]; (this: [T, T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U, U]; (this: [T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U]; (callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; } +>array : T[] +>map : { (this: [T, T, T, T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U, U, U, U]; (this: [T, T, T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U, U, U]; (this: [T, T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U, U]; (this: [T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U]; (callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; } +>x => x[key] : (x: T) => T[K] +>x : T +>x[key] : T[K] +>x : T +>key : K +} + +function f30(shapes: Shape[]) { +>f30 : (shapes: Shape[]) => void +>shapes : Shape[] +>Shape : Shape + + let names = pluck(shapes, "name"); // string[] +>names : string[] +>pluck(shapes, "name") : string[] +>pluck : (array: T[], key: K) => T[K][] +>shapes : Shape[] +>"name" : "name" + + let widths = pluck(shapes, "width"); // number[] +>widths : number[] +>pluck(shapes, "width") : number[] +>pluck : (array: T[], key: K) => T[K][] +>shapes : Shape[] +>"width" : "width" + + let nameOrVisibles = pluck(shapes, cond ? "name" : "visible"); // (string | boolean)[] +>nameOrVisibles : (string | boolean)[] +>pluck(shapes, cond ? "name" : "visible") : (string | boolean)[] +>pluck : (array: T[], key: K) => T[K][] +>shapes : Shape[] +>cond ? "name" : "visible" : "name" | "visible" +>cond : boolean +>"name" : "name" +>"visible" : "visible" +} + +function f31(key: K) { +>f31 : (key: K) => Shape[K] +>K : K +>Shape : Shape +>key : K +>K : K + + const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; +>shape : Shape +>Shape : Shape +>{ name: "foo", width: 5, height: 10, visible: true } : { name: string; width: number; height: number; visible: true; } +>name : string +>"foo" : "foo" +>width : number +>5 : 5 +>height : number +>10 : 10 +>visible : boolean +>true : true + + return shape[key]; // Shape[K] +>shape[key] : Shape[K] +>shape : Shape +>key : K +} + +function f32(key: K) { +>f32 : (key: K) => Shape[K] +>K : K +>key : K +>K : K + + const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; +>shape : Shape +>Shape : Shape +>{ name: "foo", width: 5, height: 10, visible: true } : { name: string; width: number; height: number; visible: true; } +>name : string +>"foo" : "foo" +>width : number +>5 : 5 +>height : number +>10 : 10 +>visible : boolean +>true : true + + return shape[key]; // Shape[K] +>shape[key] : Shape[K] +>shape : Shape +>key : K +} + +class C { +>C : C + + public x: string; +>x : string + + protected y: string; +>y : string + + private z: string; +>z : string +} + +// Indexed access expressions have always permitted access to private and protected members. +// For consistency we also permit such access in indexed access types. +function f40(c: C) { +>f40 : (c: C) => void +>c : C +>C : C + + type X = C["x"]; +>X : string +>C : C + + type Y = C["y"]; +>Y : string +>C : C + + type Z = C["z"]; +>Z : string +>C : C + + let x: X = c["x"]; +>x : string +>X : string +>c["x"] : string +>c : C +>"x" : "x" + + let y: Y = c["y"]; +>y : string +>Y : string +>c["y"] : string +>c : C +>"y" : "y" + + let z: Z = c["z"]; +>z : string +>Z : string +>c["z"] : string +>c : C +>"z" : "z" +} diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt new file mode 100644 index 0000000000000..23b79c16627fc --- /dev/null +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt @@ -0,0 +1,138 @@ +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(10,18): error TS2304: Cannot find name 'K0'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(20,18): error TS2339: Property 'foo' does not exist on type 'Shape'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(21,18): error TS2339: Property 'foo' does not exist on type 'Shape'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(22,18): error TS2538: Type 'any' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(23,18): error TS2537: Type 'Shape' has no matching index signature for type 'string'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(24,18): error TS2537: Type 'Shape' has no matching index signature for type 'number'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(25,18): error TS2538: Type 'boolean' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(26,18): error TS2538: Type 'void' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(27,18): error TS2538: Type 'undefined' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(28,18): error TS2538: Type '{ x: string; }' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(29,18): error TS2537: Type 'Shape' has no matching index signature for type 'string'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(30,18): error TS2538: Type 'string & number' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(31,18): error TS2537: Type 'Shape' has no matching index signature for type 'string'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(35,21): error TS2537: Type 'string[]' has no matching index signature for type 'string'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(36,21): error TS2538: Type 'boolean' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(41,31): error TS2538: Type 'boolean' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(46,16): error TS2538: Type 'boolean' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(63,33): error TS2345: Argument of type '"size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(64,33): error TS2345: Argument of type '"name" | "size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. + Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(66,24): error TS2345: Argument of type '"size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(67,24): error TS2345: Argument of type '"name" | "size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. + Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'. + + +==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (21 errors) ==== + class Shape { + name: string; + width: number; + height: number; + visible: boolean; + } + + type Dictionary = { [x: string]: T }; + + type T00 = keyof K0; // Error + ~~ +!!! error TS2304: Cannot find name 'K0'. + + type T01 = keyof Object; + type T02 = keyof keyof Object; + type T03 = keyof keyof keyof Object; + type T04 = keyof keyof keyof keyof Object; + type T05 = keyof keyof keyof keyof keyof Object; + type T06 = keyof keyof keyof keyof keyof keyof Object; + + type T10 = Shape["name"]; + type T11 = Shape["foo"]; // Error + ~~~~~ +!!! error TS2339: Property 'foo' does not exist on type 'Shape'. + type T12 = Shape["name" | "foo"]; // Error + ~~~~~~~~~~~~~~ +!!! error TS2339: Property 'foo' does not exist on type 'Shape'. + type T13 = Shape[any]; // Error + ~~~ +!!! error TS2538: Type 'any' cannot be used as an index type. + type T14 = Shape[string]; // Error + ~~~~~~ +!!! error TS2537: Type 'Shape' has no matching index signature for type 'string'. + type T15 = Shape[number]; // Error + ~~~~~~ +!!! error TS2537: Type 'Shape' has no matching index signature for type 'number'. + type T16 = Shape[boolean]; // Error + ~~~~~~~ +!!! error TS2538: Type 'boolean' cannot be used as an index type. + type T17 = Shape[void]; // Error + ~~~~ +!!! error TS2538: Type 'void' cannot be used as an index type. + type T18 = Shape[undefined]; // Error + ~~~~~~~~~ +!!! error TS2538: Type 'undefined' cannot be used as an index type. + type T19 = Shape[{ x: string }]; // Error + ~~~~~~~~~~~~~ +!!! error TS2538: Type '{ x: string; }' cannot be used as an index type. + type T20 = Shape[string | number]; // Error + ~~~~~~~~~~~~~~~ +!!! error TS2537: Type 'Shape' has no matching index signature for type 'string'. + type T21 = Shape[string & number]; // Error + ~~~~~~~~~~~~~~~ +!!! error TS2538: Type 'string & number' cannot be used as an index type. + type T22 = Shape[string | boolean]; // Error + ~~~~~~~~~~~~~~~~ +!!! error TS2537: Type 'Shape' has no matching index signature for type 'string'. + + type T30 = string[]["length"]; + type T31 = string[][number]; + type T32 = string[][string]; // Error + ~~~~~~ +!!! error TS2537: Type 'string[]' has no matching index signature for type 'string'. + type T33 = string[][boolean]; // Error + ~~~~~~~ +!!! error TS2538: Type 'boolean' cannot be used as an index type. + + type T40 = Dictionary[any]; + type T41 = Dictionary[number]; + type T42 = Dictionary[string]; + type T43 = Dictionary[boolean]; // Error + ~~~~~~~ +!!! error TS2538: Type 'boolean' cannot be used as an index type. + + type T50 = any[any]; + type T51 = any[number]; + type T52 = any[string]; + type T53 = any[boolean]; // Error + ~~~~~~~ +!!! error TS2538: Type 'boolean' cannot be used as an index type. + + type T60 = {}["toString"]; + type T61 = []["toString"]; + + declare let cond: boolean; + + function getProperty(obj: T, key: K) { + return obj[key]; + } + + function setProperty(obj: T, key: K, value: T[K]) { + obj[key] = value; + } + + function f10(shape: Shape) { + let x1 = getProperty(shape, "name"); + let x2 = getProperty(shape, "size"); // Error + ~~~~~~ +!!! error TS2345: Argument of type '"size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. + let x3 = getProperty(shape, cond ? "name" : "size"); // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '"name" | "size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. +!!! error TS2345: Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'. + setProperty(shape, "name", "rectangle"); + setProperty(shape, "size", 10); // Error + ~~~~~~ +!!! error TS2345: Argument of type '"size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. + setProperty(shape, cond ? "name" : "size", 10); // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '"name" | "size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. +!!! error TS2345: Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'. + } \ No newline at end of file diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.js b/tests/baselines/reference/keyofAndIndexedAccessErrors.js new file mode 100644 index 0000000000000..145d8e3f14898 --- /dev/null +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.js @@ -0,0 +1,90 @@ +//// [keyofAndIndexedAccessErrors.ts] +class Shape { + name: string; + width: number; + height: number; + visible: boolean; +} + +type Dictionary = { [x: string]: T }; + +type T00 = keyof K0; // Error + +type T01 = keyof Object; +type T02 = keyof keyof Object; +type T03 = keyof keyof keyof Object; +type T04 = keyof keyof keyof keyof Object; +type T05 = keyof keyof keyof keyof keyof Object; +type T06 = keyof keyof keyof keyof keyof keyof Object; + +type T10 = Shape["name"]; +type T11 = Shape["foo"]; // Error +type T12 = Shape["name" | "foo"]; // Error +type T13 = Shape[any]; // Error +type T14 = Shape[string]; // Error +type T15 = Shape[number]; // Error +type T16 = Shape[boolean]; // Error +type T17 = Shape[void]; // Error +type T18 = Shape[undefined]; // Error +type T19 = Shape[{ x: string }]; // Error +type T20 = Shape[string | number]; // Error +type T21 = Shape[string & number]; // Error +type T22 = Shape[string | boolean]; // Error + +type T30 = string[]["length"]; +type T31 = string[][number]; +type T32 = string[][string]; // Error +type T33 = string[][boolean]; // Error + +type T40 = Dictionary[any]; +type T41 = Dictionary[number]; +type T42 = Dictionary[string]; +type T43 = Dictionary[boolean]; // Error + +type T50 = any[any]; +type T51 = any[number]; +type T52 = any[string]; +type T53 = any[boolean]; // Error + +type T60 = {}["toString"]; +type T61 = []["toString"]; + +declare let cond: boolean; + +function getProperty(obj: T, key: K) { + return obj[key]; +} + +function setProperty(obj: T, key: K, value: T[K]) { + obj[key] = value; +} + +function f10(shape: Shape) { + let x1 = getProperty(shape, "name"); + let x2 = getProperty(shape, "size"); // Error + let x3 = getProperty(shape, cond ? "name" : "size"); // Error + setProperty(shape, "name", "rectangle"); + setProperty(shape, "size", 10); // Error + setProperty(shape, cond ? "name" : "size", 10); // Error +} + +//// [keyofAndIndexedAccessErrors.js] +var Shape = (function () { + function Shape() { + } + return Shape; +}()); +function getProperty(obj, key) { + return obj[key]; +} +function setProperty(obj, key, value) { + obj[key] = value; +} +function f10(shape) { + var x1 = getProperty(shape, "name"); + var x2 = getProperty(shape, "size"); // Error + var x3 = getProperty(shape, cond ? "name" : "size"); // Error + setProperty(shape, "name", "rectangle"); + setProperty(shape, "size", 10); // Error + setProperty(shape, cond ? "name" : "size", 10); // Error +} diff --git a/tests/baselines/reference/noImplicitAnyForIn.errors.txt b/tests/baselines/reference/noImplicitAnyForIn.errors.txt index 69b5cd34906fd..3db1c260d517c 100644 --- a/tests/baselines/reference/noImplicitAnyForIn.errors.txt +++ b/tests/baselines/reference/noImplicitAnyForIn.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/noImplicitAnyForIn.ts(8,18): error TS7017: Index signature of object type implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyForIn.ts(15,18): error TS7017: Index signature of object type implicitly has an 'any' type. +tests/cases/compiler/noImplicitAnyForIn.ts(8,18): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +tests/cases/compiler/noImplicitAnyForIn.ts(15,18): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. tests/cases/compiler/noImplicitAnyForIn.ts(29,5): error TS7005: Variable 'n' implicitly has an 'any[][]' type. tests/cases/compiler/noImplicitAnyForIn.ts(31,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. @@ -14,7 +14,7 @@ tests/cases/compiler/noImplicitAnyForIn.ts(31,6): error TS2405: The left-hand si //Should yield an implicit 'any' error var _j = x[i][j]; ~~~~~~~ -!!! error TS7017: Index signature of object type implicitly has an 'any' type. +!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. } for (var k in x[0]) { @@ -23,7 +23,7 @@ tests/cases/compiler/noImplicitAnyForIn.ts(31,6): error TS2405: The left-hand si //Should yield an implicit 'any' error var k2 = k1[k]; ~~~~~ -!!! error TS7017: Index signature of object type implicitly has an 'any' type. +!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. } } diff --git a/tests/baselines/reference/noImplicitAnyIndexing.errors.txt b/tests/baselines/reference/noImplicitAnyIndexing.errors.txt index 8f4cf616bda5f..3274bec5aae49 100644 --- a/tests/baselines/reference/noImplicitAnyIndexing.errors.txt +++ b/tests/baselines/reference/noImplicitAnyIndexing.errors.txt @@ -1,7 +1,7 @@ -tests/cases/compiler/noImplicitAnyIndexing.ts(13,26): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. -tests/cases/compiler/noImplicitAnyIndexing.ts(20,9): error TS7017: Index signature of object type implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyIndexing.ts(23,9): error TS7017: Index signature of object type implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyIndexing.ts(31,10): error TS7017: Index signature of object type implicitly has an 'any' type. +tests/cases/compiler/noImplicitAnyIndexing.ts(13,37): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. +tests/cases/compiler/noImplicitAnyIndexing.ts(20,9): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +tests/cases/compiler/noImplicitAnyIndexing.ts(23,9): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +tests/cases/compiler/noImplicitAnyIndexing.ts(31,10): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. ==== tests/cases/compiler/noImplicitAnyIndexing.ts (4 errors) ==== @@ -18,7 +18,7 @@ tests/cases/compiler/noImplicitAnyIndexing.ts(31,10): error TS7017: Index signat // Should be implicit 'any' ; property access fails, no string indexer. var strRepresentation3 = MyEmusEnum["monehh"]; - ~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~ !!! error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. // Should be okay; should be a MyEmusEnum @@ -28,12 +28,12 @@ tests/cases/compiler/noImplicitAnyIndexing.ts(31,10): error TS7017: Index signat // Should report an implicit 'any'. var x = {}["hi"]; ~~~~~~~~ -!!! error TS7017: Index signature of object type implicitly has an 'any' type. +!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. // Should report an implicit 'any'. var y = {}[10]; ~~~~~~ -!!! error TS7017: Index signature of object type implicitly has an 'any' type. +!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. var hi: any = "hi"; @@ -43,7 +43,7 @@ tests/cases/compiler/noImplicitAnyIndexing.ts(31,10): error TS7017: Index signat // Should report an implicit 'any'. var z1 = emptyObj[hi]; ~~~~~~~~~~~~ -!!! error TS7017: Index signature of object type implicitly has an 'any' type. +!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. var z2 = (emptyObj)[hi]; interface MyMap { diff --git a/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.errors.txt b/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.errors.txt index 5c0878f8ab940..c66a0a831082c 100644 --- a/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.errors.txt +++ b/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.errors.txt @@ -1,8 +1,8 @@ -tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(2,9): error TS7017: Index signature of object type implicitly has an 'any' type. +tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(2,9): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. ==== tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts (1 errors) ==== var x = {}["hello"]; ~~~~~~~~~~~ -!!! error TS7017: Index signature of object type implicitly has an 'any' type. \ No newline at end of file +!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. \ No newline at end of file diff --git a/tests/baselines/reference/nullAssignedToUndefined.errors.txt b/tests/baselines/reference/nullAssignedToUndefined.errors.txt index 5f9921b58097b..88bd04a1e628e 100644 --- a/tests/baselines/reference/nullAssignedToUndefined.errors.txt +++ b/tests/baselines/reference/nullAssignedToUndefined.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/types/typeRelationships/assignmentCompatibility/nullAssignedToUndefined.ts(1,9): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/nullAssignedToUndefined.ts(1,9): error TS2539: Cannot assign to 'undefined' because it is not a variable. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/nullAssignedToUndefined.ts (1 errors) ==== var x = undefined = null; // error ~~~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'undefined' because it is not a variable. var y: typeof undefined = null; // ok, widened \ No newline at end of file diff --git a/tests/baselines/reference/numericLiteralTypes1.types b/tests/baselines/reference/numericLiteralTypes1.types index 56e4bcc0f3fc1..49c521ad15f35 100644 --- a/tests/baselines/reference/numericLiteralTypes1.types +++ b/tests/baselines/reference/numericLiteralTypes1.types @@ -202,11 +202,11 @@ function f4(a: 1, b: 0 | 1 | 2) { a++; >a++ : number ->a : 1 +>a : number b++; >b++ : number ->b : 0 | 1 | 2 +>b : number } declare function g(x: 0): string; diff --git a/tests/baselines/reference/numericLiteralTypes2.types b/tests/baselines/reference/numericLiteralTypes2.types index b8e2526a221fc..4c67154ad411b 100644 --- a/tests/baselines/reference/numericLiteralTypes2.types +++ b/tests/baselines/reference/numericLiteralTypes2.types @@ -203,11 +203,11 @@ function f4(a: 1, b: 0 | 1 | 2) { a++; >a++ : number ->a : 1 +>a : number b++; >b++ : number ->b : 0 | 1 | 2 +>b : number } declare function g(x: 0): string; diff --git a/tests/baselines/reference/objectCreationOfElementAccessExpression.errors.txt b/tests/baselines/reference/objectCreationOfElementAccessExpression.errors.txt index ef50db9e4e5eb..fecbee27b58b3 100644 --- a/tests/baselines/reference/objectCreationOfElementAccessExpression.errors.txt +++ b/tests/baselines/reference/objectCreationOfElementAccessExpression.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/objectCreationOfElementAccessExpression.ts(53,17): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/compiler/objectCreationOfElementAccessExpression.ts(53,25): error TS2538: Type 'Cookie' cannot be used as an index type. tests/cases/compiler/objectCreationOfElementAccessExpression.ts(53,63): error TS2348: Value of type 'typeof Cookie' is not callable. Did you mean to include 'new'? -tests/cases/compiler/objectCreationOfElementAccessExpression.ts(54,33): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/compiler/objectCreationOfElementAccessExpression.ts(54,41): error TS2538: Type 'Cookie' cannot be used as an index type. tests/cases/compiler/objectCreationOfElementAccessExpression.ts(54,79): error TS2348: Value of type 'typeof Cookie' is not callable. Did you mean to include 'new'? @@ -58,13 +58,13 @@ tests/cases/compiler/objectCreationOfElementAccessExpression.ts(54,79): error TS // ElementAccessExpressions can only contain one expression. There should be a parse error here. var foods = new PetFood[new IceCream('Mint chocolate chip') , Cookie('Chocolate chip', false) , new Cookie('Peanut butter', true)]; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2538: Type 'Cookie' cannot be used as an index type. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2348: Value of type 'typeof Cookie' is not callable. Did you mean to include 'new'? var foods2: MonsterFood[] = new PetFood[new IceCream('Mint chocolate chip') , Cookie('Chocolate chip', false) , new Cookie('Peanut butter', true)]; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2538: Type 'Cookie' cannot be used as an index type. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2348: Value of type 'typeof Cookie' is not callable. Did you mean to include 'new'? \ No newline at end of file diff --git a/tests/baselines/reference/objectTypeWithStringNamedNumericProperty.types b/tests/baselines/reference/objectTypeWithStringNamedNumericProperty.types index 5e664fadd2092..e050d33024c54 100644 --- a/tests/baselines/reference/objectTypeWithStringNamedNumericProperty.types +++ b/tests/baselines/reference/objectTypeWithStringNamedNumericProperty.types @@ -84,15 +84,15 @@ var r3 = c[1.0]; // same as indexing by 1 when done numerically // BUG 823822 var r7 = i[-1]; ->r7 : any ->i[-1] : any +>r7 : Date +>i[-1] : Date >i : I >-1 : -1 >1 : 1 var r7 = i[-1.0]; ->r7 : any ->i[-1.0] : any +>r7 : Date +>i[-1.0] : Date >i : I >-1.0 : -1 >1.0 : 1 @@ -116,8 +116,8 @@ var r10 = i[0x1] >0x1 : 1 var r11 = i[-0x1] ->r11 : any ->i[-0x1] : any +>r11 : Date +>i[-0x1] : Date >i : I >-0x1 : -1 >0x1 : 1 @@ -129,8 +129,8 @@ var r12 = i[01] >01 : 1 var r13 = i[-01] ->r13 : any ->i[-01] : any +>r13 : Date +>i[-01] : Date >i : I >-01 : -1 >01 : 1 @@ -215,15 +215,15 @@ var r3 = c[1.0]; // same as indexing by 1 when done numerically // BUG 823822 var r7 = i[-1]; ->r7 : any ->i[-1] : any +>r7 : Date +>i[-1] : Date >i : I >-1 : -1 >1 : 1 var r7 = i[-1.0]; ->r7 : any ->i[-1.0] : any +>r7 : Date +>i[-1.0] : Date >i : I >-1.0 : -1 >1.0 : 1 @@ -247,8 +247,8 @@ var r10 = i[0x1] >0x1 : 1 var r11 = i[-0x1] ->r11 : any ->i[-0x1] : any +>r11 : Date +>i[-0x1] : Date >i : I >-0x1 : -1 >0x1 : 1 @@ -260,8 +260,8 @@ var r12 = i[01] >01 : 1 var r13 = i[-01] ->r13 : any ->i[-01] : any +>r13 : Date +>i[-01] : Date >i : I >-01 : -1 >01 : 1 @@ -342,15 +342,15 @@ var r3 = c[1.0]; // same as indexing by 1 when done numerically // BUG 823822 var r7 = i[-1]; ->r7 : any ->i[-1] : any +>r7 : Date +>i[-1] : Date >i : I >-1 : -1 >1 : 1 var r7 = i[-1.0]; ->r7 : any ->i[-1.0] : any +>r7 : Date +>i[-1.0] : Date >i : I >-1.0 : -1 >1.0 : 1 @@ -374,8 +374,8 @@ var r10 = i[0x1] >0x1 : 1 var r11 = i[-0x1] ->r11 : any ->i[-0x1] : any +>r11 : Date +>i[-0x1] : Date >i : I >-0x1 : -1 >0x1 : 1 @@ -387,8 +387,8 @@ var r12 = i[01] >01 : 1 var r13 = i[-01] ->r13 : any ->i[-01] : any +>r13 : Date +>i[-01] : Date >i : I >-01 : -1 >01 : 1 @@ -482,15 +482,15 @@ var r3 = c[1.0]; // same as indexing by 1 when done numerically // BUG 823822 var r7 = i[-1]; ->r7 : any ->i[-1] : any +>r7 : Date +>i[-1] : Date >i : I >-1 : -1 >1 : 1 var r7 = i[-1.0]; ->r7 : any ->i[-1.0] : any +>r7 : Date +>i[-1.0] : Date >i : I >-1.0 : -1 >1.0 : 1 @@ -514,8 +514,8 @@ var r10 = i[0x1] >0x1 : 1 var r11 = i[-0x1] ->r11 : any ->i[-0x1] : any +>r11 : Date +>i[-0x1] : Date >i : I >-0x1 : -1 >0x1 : 1 @@ -527,8 +527,8 @@ var r12 = i[01] >01 : 1 var r13 = i[-01] ->r13 : any ->i[-01] : any +>r13 : Date +>i[-01] : Date >i : I >-01 : -1 >01 : 1 diff --git a/tests/baselines/reference/parserAssignmentExpression1.errors.txt b/tests/baselines/reference/parserAssignmentExpression1.errors.txt index 70eecd81b39e6..4a5891eb6a99e 100644 --- a/tests/baselines/reference/parserAssignmentExpression1.errors.txt +++ b/tests/baselines/reference/parserAssignmentExpression1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/parser/ecmascript5/Expressions/parserAssignmentExpression1.ts(1,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/parser/ecmascript5/Expressions/parserAssignmentExpression1.ts(1,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/parser/ecmascript5/Expressions/parserAssignmentExpression1.ts(1,2): error TS2304: Cannot find name 'foo'. tests/cases/conformance/parser/ecmascript5/Expressions/parserAssignmentExpression1.ts(1,11): error TS2304: Cannot find name 'bar'. @@ -6,7 +6,7 @@ tests/cases/conformance/parser/ecmascript5/Expressions/parserAssignmentExpressio ==== tests/cases/conformance/parser/ecmascript5/Expressions/parserAssignmentExpression1.ts (3 errors) ==== (foo()) = bar; ~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ~~~ !!! error TS2304: Cannot find name 'foo'. ~~~ diff --git a/tests/baselines/reference/parserForStatement2.errors.txt b/tests/baselines/reference/parserForStatement2.errors.txt index 59d6dd6dec8f4..68ab999b657a5 100644 --- a/tests/baselines/reference/parserForStatement2.errors.txt +++ b/tests/baselines/reference/parserForStatement2.errors.txt @@ -1,11 +1,17 @@ +tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement2.ts(4,13): error TS2538: Type 'undefined' cannot be used as an index type. +tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement2.ts(4,20): error TS2538: Type 'undefined' cannot be used as an index type. tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement2.ts(4,30): error TS2304: Cannot find name 'd'. -==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement2.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement2.ts (3 errors) ==== var a; var b = []; var c; for (a in b[c] = b[c] || [], d) { + ~ +!!! error TS2538: Type 'undefined' cannot be used as an index type. + ~ +!!! error TS2538: Type 'undefined' cannot be used as an index type. ~ !!! error TS2304: Cannot find name 'd'. diff --git a/tests/baselines/reference/parserForStatement6.errors.txt b/tests/baselines/reference/parserForStatement6.errors.txt index a41f103e929ca..808a166afad46 100644 --- a/tests/baselines/reference/parserForStatement6.errors.txt +++ b/tests/baselines/reference/parserForStatement6.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement6.ts(1,6): error TS2304: Cannot find name 'foo'. -tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement6.ts(1,6): error TS2406: Invalid left-hand side in 'for...in' statement. +tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement6.ts(1,6): error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access. tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement6.ts(1,15): error TS2304: Cannot find name 'b'. @@ -8,7 +8,7 @@ tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement6.ts(1,1 ~~~ !!! error TS2304: Cannot find name 'foo'. ~~~~~ -!!! error TS2406: Invalid left-hand side in 'for...in' statement. +!!! error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access. ~ !!! error TS2304: Cannot find name 'b'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForStatement7.errors.txt b/tests/baselines/reference/parserForStatement7.errors.txt index 3aa67480105aa..1fd3648074415 100644 --- a/tests/baselines/reference/parserForStatement7.errors.txt +++ b/tests/baselines/reference/parserForStatement7.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement7.ts(1,6): error TS2406: Invalid left-hand side in 'for...in' statement. +tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement7.ts(1,6): error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access. tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement7.ts(1,10): error TS2304: Cannot find name 'foo'. tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement7.ts(1,19): error TS2304: Cannot find name 'b'. @@ -6,7 +6,7 @@ tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement7.ts(1,1 ==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement7.ts (3 errors) ==== for (new foo() in b) { ~~~~~~~~~ -!!! error TS2406: Invalid left-hand side in 'for...in' statement. +!!! error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access. ~~~ !!! error TS2304: Cannot find name 'foo'. ~ diff --git a/tests/baselines/reference/parserForStatement8.errors.txt b/tests/baselines/reference/parserForStatement8.errors.txt index 72c7901aa8c53..21ea55e3b09f1 100644 --- a/tests/baselines/reference/parserForStatement8.errors.txt +++ b/tests/baselines/reference/parserForStatement8.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts(1,6): error TS2406: Invalid left-hand side in 'for...in' statement. +tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts(1,6): error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access. tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts(1,14): error TS2304: Cannot find name 'b'. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts (2 errors) ==== for (this in b) { ~~~~ -!!! error TS2406: Invalid left-hand side in 'for...in' statement. +!!! error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access. ~ !!! error TS2304: Cannot find name 'b'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserGreaterThanTokenAmbiguity11.errors.txt b/tests/baselines/reference/parserGreaterThanTokenAmbiguity11.errors.txt index 8ccafdaf094a6..2c179256c77c0 100644 --- a/tests/baselines/reference/parserGreaterThanTokenAmbiguity11.errors.txt +++ b/tests/baselines/reference/parserGreaterThanTokenAmbiguity11.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity11.ts(1,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity11.ts(1,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ==== tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity11.ts (1 errors) ==== 1 >>= 2; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/parserGreaterThanTokenAmbiguity15.errors.txt b/tests/baselines/reference/parserGreaterThanTokenAmbiguity15.errors.txt index 12bba7ec8f55c..3c2c9c45d3396 100644 --- a/tests/baselines/reference/parserGreaterThanTokenAmbiguity15.errors.txt +++ b/tests/baselines/reference/parserGreaterThanTokenAmbiguity15.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity15.ts(1,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity15.ts(1,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ==== tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity15.ts (1 errors) ==== 1 ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // before >>= // after 2; \ No newline at end of file diff --git a/tests/baselines/reference/parserGreaterThanTokenAmbiguity16.errors.txt b/tests/baselines/reference/parserGreaterThanTokenAmbiguity16.errors.txt index eb31b49621e9c..fd2f07bda819c 100644 --- a/tests/baselines/reference/parserGreaterThanTokenAmbiguity16.errors.txt +++ b/tests/baselines/reference/parserGreaterThanTokenAmbiguity16.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity16.ts(1,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity16.ts(1,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ==== tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity16.ts (1 errors) ==== 1 >>>= 2; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/parserGreaterThanTokenAmbiguity20.errors.txt b/tests/baselines/reference/parserGreaterThanTokenAmbiguity20.errors.txt index c464bc37ff85c..d5aa2b1269bb9 100644 --- a/tests/baselines/reference/parserGreaterThanTokenAmbiguity20.errors.txt +++ b/tests/baselines/reference/parserGreaterThanTokenAmbiguity20.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity20.ts(1,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity20.ts(1,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ==== tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity20.ts (1 errors) ==== 1 ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // Before >>>= // after 2; \ No newline at end of file diff --git a/tests/baselines/reference/parserStrictMode3-negative.errors.txt b/tests/baselines/reference/parserStrictMode3-negative.errors.txt index 464f6859de6dd..4ea779d5fdc19 100644 --- a/tests/baselines/reference/parserStrictMode3-negative.errors.txt +++ b/tests/baselines/reference/parserStrictMode3-negative.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode3-negative.ts(1,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode3-negative.ts(1,1): error TS2539: Cannot assign to 'eval' because it is not a variable. ==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode3-negative.ts (1 errors) ==== eval = 1; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/parserStrictMode3.errors.txt b/tests/baselines/reference/parserStrictMode3.errors.txt index b8f1e0f54b8df..688aa6e462bce 100644 --- a/tests/baselines/reference/parserStrictMode3.errors.txt +++ b/tests/baselines/reference/parserStrictMode3.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode3.ts(2,1): error TS1100: Invalid use of 'eval' in strict mode. -tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode3.ts(2,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode3.ts(2,1): error TS2539: Cannot assign to 'eval' because it is not a variable. ==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode3.ts (2 errors) ==== @@ -8,4 +8,4 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode3.ts(2,1): ~~~~ !!! error TS1100: Invalid use of 'eval' in strict mode. ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/parserStrictMode5.errors.txt b/tests/baselines/reference/parserStrictMode5.errors.txt index e541963a1fb5f..d3b0ab3f44a8c 100644 --- a/tests/baselines/reference/parserStrictMode5.errors.txt +++ b/tests/baselines/reference/parserStrictMode5.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode5.ts(2,1): error TS1100: Invalid use of 'eval' in strict mode. -tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode5.ts(2,1): error TS2365: Operator '+=' cannot be applied to types '(x: string) => any' and '1'. +tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode5.ts(2,1): error TS2539: Cannot assign to 'eval' because it is not a variable. ==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode5.ts (2 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode5.ts(2,1): eval += 1; ~~~~ !!! error TS1100: Invalid use of 'eval' in strict mode. - ~~~~~~~~~ -!!! error TS2365: Operator '+=' cannot be applied to types '(x: string) => any' and '1'. \ No newline at end of file + ~~~~ +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/parserStrictMode6-negative.errors.txt b/tests/baselines/reference/parserStrictMode6-negative.errors.txt index 69d7d1317299f..df373be0301f0 100644 --- a/tests/baselines/reference/parserStrictMode6-negative.errors.txt +++ b/tests/baselines/reference/parserStrictMode6-negative.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode6-negative.ts(1,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode6-negative.ts(1,1): error TS2539: Cannot assign to 'eval' because it is not a variable. ==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode6-negative.ts (1 errors) ==== eval++; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. \ No newline at end of file +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/parserStrictMode6.errors.txt b/tests/baselines/reference/parserStrictMode6.errors.txt index 7ac0e7fdb4d17..2a8fda7f62f8f 100644 --- a/tests/baselines/reference/parserStrictMode6.errors.txt +++ b/tests/baselines/reference/parserStrictMode6.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode6.ts(2,1): error TS1100: Invalid use of 'eval' in strict mode. -tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode6.ts(2,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode6.ts(2,1): error TS2539: Cannot assign to 'eval' because it is not a variable. ==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode6.ts (2 errors) ==== @@ -8,4 +8,4 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode6.ts(2,1): ~~~~ !!! error TS1100: Invalid use of 'eval' in strict mode. ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. \ No newline at end of file +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/parserStrictMode7.errors.txt b/tests/baselines/reference/parserStrictMode7.errors.txt index 6ee6ca4304292..b4ea09f14d429 100644 --- a/tests/baselines/reference/parserStrictMode7.errors.txt +++ b/tests/baselines/reference/parserStrictMode7.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts(2,3): error TS1100: Invalid use of 'eval' in strict mode. -tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts(2,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts(2,3): error TS2539: Cannot assign to 'eval' because it is not a variable. ==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts (2 errors) ==== @@ -8,4 +8,4 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts(2,3): ~~~~ !!! error TS1100: Invalid use of 'eval' in strict mode. ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. \ No newline at end of file +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/parserUnaryExpression1.errors.txt b/tests/baselines/reference/parserUnaryExpression1.errors.txt index 16900ea616076..278960d53f31b 100644 --- a/tests/baselines/reference/parserUnaryExpression1.errors.txt +++ b/tests/baselines/reference/parserUnaryExpression1.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression1.ts(1,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression1.ts(1,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ==== tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression1.ts (1 errors) ==== ++this; ~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. \ No newline at end of file +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/parserUnaryExpression7.errors.txt b/tests/baselines/reference/parserUnaryExpression7.errors.txt index 32967d2e0b80b..f69f8e882525f 100644 --- a/tests/baselines/reference/parserUnaryExpression7.errors.txt +++ b/tests/baselines/reference/parserUnaryExpression7.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression7.ts(1,4): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression7.ts(1,4): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression7.ts(1,8): error TS2304: Cannot find name 'Foo'. ==== tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression7.ts (2 errors) ==== ++ new Foo(); ~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~ !!! error TS2304: Cannot find name 'Foo'. \ No newline at end of file diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.errors.txt b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.errors.txt index 6d95ac42c8f10..99e7b193f0c42 100644 --- a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.errors.txt +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.errors.txt @@ -1,5 +1,5 @@ maxDepthExceeded/root.ts(3,1): error TS2322: Type '"10"' is not assignable to type 'number'. -maxDepthExceeded/root.ts(4,1): error TS2322: Type '42' is not assignable to type 'true'. +maxDepthExceeded/root.ts(4,4): error TS2540: Cannot assign to 'rel' because it is a constant or a read-only property. ==== entry.js (0 errors) ==== @@ -36,8 +36,8 @@ maxDepthExceeded/root.ts(4,1): error TS2322: Type '42' is not assignable to type ~~~~~~~ !!! error TS2322: Type '"10"' is not assignable to type 'number'. m1.rel = 42; // Error: Should be boolean - ~~~~~~ -!!! error TS2322: Type '42' is not assignable to type 'true'. + ~~~ +!!! error TS2540: Cannot assign to 'rel' because it is a constant or a read-only property. m1.f2.person.age = "10"; // OK if stopped at 2 modules: person will be "any". \ No newline at end of file diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.errors.txt b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.errors.txt index 6d95ac42c8f10..99e7b193f0c42 100644 --- a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.errors.txt +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.errors.txt @@ -1,5 +1,5 @@ maxDepthExceeded/root.ts(3,1): error TS2322: Type '"10"' is not assignable to type 'number'. -maxDepthExceeded/root.ts(4,1): error TS2322: Type '42' is not assignable to type 'true'. +maxDepthExceeded/root.ts(4,4): error TS2540: Cannot assign to 'rel' because it is a constant or a read-only property. ==== entry.js (0 errors) ==== @@ -36,8 +36,8 @@ maxDepthExceeded/root.ts(4,1): error TS2322: Type '42' is not assignable to type ~~~~~~~ !!! error TS2322: Type '"10"' is not assignable to type 'number'. m1.rel = 42; // Error: Should be boolean - ~~~~~~ -!!! error TS2322: Type '42' is not assignable to type 'true'. + ~~~ +!!! error TS2540: Cannot assign to 'rel' because it is a constant or a read-only property. m1.f2.person.age = "10"; // OK if stopped at 2 modules: person will be "any". \ No newline at end of file diff --git a/tests/baselines/reference/propertyAccess.errors.txt b/tests/baselines/reference/propertyAccess.errors.txt index b32449561743c..a183ad79c1129 100644 --- a/tests/baselines/reference/propertyAccess.errors.txt +++ b/tests/baselines/reference/propertyAccess.errors.txt @@ -1,12 +1,13 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(11,55): error TS2322: Type '{ 3: string; 'three': string; }' is not assignable to type '{ [n: number]: string; }'. Object literal may only specify known properties, and ''three'' does not exist in type '{ [n: number]: string; }'. tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(45,14): error TS2339: Property 'qqq' does not exist on type '{ 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }'. -tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(80,10): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. -tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(117,10): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. -tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,12): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(80,19): error TS2538: Type '{ name: string; }' cannot be used as an index type. +tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(117,18): error TS2538: Type '{ name: string; }' cannot be used as an index type. +tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,22): error TS2538: Type '{ name: string; }' cannot be used as an index type. +tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(149,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'x3' must be of type 'A | B', but here has type 'A'. -==== tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts (5 errors) ==== +==== tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts (6 errors) ==== class A { a: number; } @@ -92,8 +93,8 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,12): er // Bracket notation property access using value of other type on type with numeric index signature and no string index signature var ll = numIndex[someObject]; // Error - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~~~~~~~ +!!! error TS2538: Type '{ name: string; }' cannot be used as an index type. // Bracket notation property access using string value on type with string index signature and no numeric index signature var mm = strIndex['N']; @@ -131,8 +132,8 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,12): er // Bracket notation property access using values of other types on type with no index signatures var uu = noIndex[someObject]; // Error - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~~~~~~~ +!!! error TS2538: Type '{ name: string; }' cannot be used as an index type. // Bracket notation property access using numeric value on type with numeric index signature and string index signature var vv = noIndex[32]; @@ -156,8 +157,8 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,12): er // Bracket notation property access using value of other type on type with numeric index signature and no string index signature and string index signature var zzzz = bothIndex[someObject]; // Error - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~~~~~~~ +!!! error TS2538: Type '{ name: string; }' cannot be used as an index type. var x1 = numIndex[stringOrNumber]; var x1: any; @@ -167,4 +168,6 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,12): er var x3 = bothIndex[stringOrNumber]; var x3: A; + ~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x3' must be of type 'A | B', but here has type 'A'. \ No newline at end of file diff --git a/tests/baselines/reference/readonlyConstructorAssignment.errors.txt b/tests/baselines/reference/readonlyConstructorAssignment.errors.txt index e764fe21edaeb..31b4ad969cb91 100644 --- a/tests/baselines/reference/readonlyConstructorAssignment.errors.txt +++ b/tests/baselines/reference/readonlyConstructorAssignment.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyConstructorAssignment.ts(13,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyConstructorAssignment.ts(13,14): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyConstructorAssignment.ts(33,7): error TS2415: Class 'E' incorrectly extends base class 'D'. Property 'x' is private in type 'D' but not in type 'E'. @@ -17,8 +17,8 @@ tests/cases/conformance/classes/constructorDeclarations/constructorParameters/re super(x); // Fails, x is readonly this.x = 1; - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. } } diff --git a/tests/baselines/reference/readonlyInConstructorParameters.errors.txt b/tests/baselines/reference/readonlyInConstructorParameters.errors.txt index 6e4b549ce74ec..15d0d0be8eb32 100644 --- a/tests/baselines/reference/readonlyInConstructorParameters.errors.txt +++ b/tests/baselines/reference/readonlyInConstructorParameters.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInConstructorParameters.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInConstructorParameters.ts(4,10): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInConstructorParameters.ts(7,26): error TS1029: 'public' modifier must precede 'readonly' modifier. tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInConstructorParameters.ts(13,10): error TS2341: Property 'x' is private and only accessible within class 'F'. @@ -8,8 +8,8 @@ tests/cases/conformance/classes/constructorDeclarations/constructorParameters/re constructor(readonly x: number) {} } new C(1).x = 2; - ~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. class E { constructor(readonly public x: number) {} diff --git a/tests/baselines/reference/readonlyMembers.errors.txt b/tests/baselines/reference/readonlyMembers.errors.txt index 7bc10aa374690..7a6b74359d16e 100644 --- a/tests/baselines/reference/readonlyMembers.errors.txt +++ b/tests/baselines/reference/readonlyMembers.errors.txt @@ -1,18 +1,18 @@ -tests/cases/compiler/readonlyMembers.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(17,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(19,13): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(20,13): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(21,13): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(25,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(26,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(27,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(36,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(40,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(49,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(56,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(62,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(65,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(7,3): error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(8,3): error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(17,14): error TS2540: Cannot assign to 'c' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(19,18): error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(20,18): error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(21,18): error TS2540: Cannot assign to 'c' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(25,14): error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(26,14): error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(27,14): error TS2540: Cannot assign to 'c' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(36,3): error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(40,3): error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(49,3): error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(56,3): error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(62,1): error TS2542: Index signature in type '{ readonly [x: string]: string; }' only permits reading. +tests/cases/compiler/readonlyMembers.ts(65,1): error TS2542: Index signature in type '{ [x: string]: string; readonly [x: number]: string; }' only permits reading. ==== tests/cases/compiler/readonlyMembers.ts (15 errors) ==== @@ -23,11 +23,11 @@ tests/cases/compiler/readonlyMembers.ts(65,1): error TS2450: Left-hand side of a } var x: X = { a: 0 }; x.a = 1; // Error - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. x.b = 1; // Error - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. class C { readonly a: number; @@ -37,30 +37,30 @@ tests/cases/compiler/readonlyMembers.ts(65,1): error TS2450: Left-hand side of a this.a = 1; // Ok this.b = 1; // Ok this.c = 1; // Error - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'c' because it is a constant or a read-only property. const f = () => { this.a = 1; // Error - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. this.b = 1; // Error - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. this.c = 1; // Error - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'c' because it is a constant or a read-only property. } } foo() { this.a = 1; // Error - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. this.b = 1; // Error - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. this.c = 1; // Error - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'c' because it is a constant or a read-only property. } } @@ -70,14 +70,14 @@ tests/cases/compiler/readonlyMembers.ts(65,1): error TS2450: Left-hand side of a set b(value) { } }; o.a = 1; // Error - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. o.b = 1; var p: { readonly a: number, b: number } = { a: 1, b: 1 }; p.a = 1; // Error - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. p.b = 1; var q: { a: number, b: number } = p; q.a = 1; @@ -87,8 +87,8 @@ tests/cases/compiler/readonlyMembers.ts(65,1): error TS2450: Left-hand side of a A, B, C } E.A = 1; // Error - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. namespace N { export const a = 1; @@ -96,8 +96,8 @@ tests/cases/compiler/readonlyMembers.ts(65,1): error TS2450: Left-hand side of a export var c = 1; } N.a = 1; // Error - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. N.b = 1; N.c = 1; @@ -105,10 +105,10 @@ tests/cases/compiler/readonlyMembers.ts(65,1): error TS2450: Left-hand side of a let s = xx["foo"]; xx["foo"] = "abc"; // Error ~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2542: Index signature in type '{ readonly [x: string]: string; }' only permits reading. let yy: { readonly [x: number]: string, [x: string]: string }; yy[1] = "abc"; // Error ~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2542: Index signature in type '{ [x: string]: string; readonly [x: number]: string; }' only permits reading. yy["foo"] = "abc"; \ No newline at end of file diff --git a/tests/baselines/reference/redefineArray.errors.txt b/tests/baselines/reference/redefineArray.errors.txt index 82ef91807c28b..6a9cf95479891 100644 --- a/tests/baselines/reference/redefineArray.errors.txt +++ b/tests/baselines/reference/redefineArray.errors.txt @@ -1,7 +1,7 @@ -tests/cases/compiler/redefineArray.ts(1,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/redefineArray.ts(1,1): error TS2540: Cannot assign to 'Array' because it is a constant or a read-only property. ==== tests/cases/compiler/redefineArray.ts (1 errors) ==== Array = function (n:number, s:string) {return n;}; ~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. \ No newline at end of file +!!! error TS2540: Cannot assign to 'Array' because it is a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationIfElse.types b/tests/baselines/reference/sourceMapValidationIfElse.types index 87103b792e7c1..b4a76d5564738 100644 --- a/tests/baselines/reference/sourceMapValidationIfElse.types +++ b/tests/baselines/reference/sourceMapValidationIfElse.types @@ -10,7 +10,7 @@ if (i == 10) { i++; >i++ : number ->i : 10 +>i : number } else { @@ -22,7 +22,7 @@ if (i == 10) { i++; >i++ : number ->i : 10 +>i : number } else if (i == 20) { >i == 20 : boolean @@ -31,7 +31,7 @@ else if (i == 20) { i--; >i-- : number ->i : 20 +>i : number } else if (i == 30) { >i == 30 : boolean diff --git a/tests/baselines/reference/sourceMapValidationSwitch.types b/tests/baselines/reference/sourceMapValidationSwitch.types index 359cabbfabe56..9df86ee213251 100644 --- a/tests/baselines/reference/sourceMapValidationSwitch.types +++ b/tests/baselines/reference/sourceMapValidationSwitch.types @@ -11,7 +11,7 @@ switch (x) { x++; >x++ : number ->x : 5 +>x : number break; case 10: @@ -19,7 +19,7 @@ switch (x) { { x--; >x-- : number ->x : 10 +>x : number break; } @@ -39,7 +39,7 @@ switch (x) x++; >x++ : number ->x : 5 +>x : number break; case 10: @@ -47,7 +47,7 @@ switch (x) { x--; >x-- : number ->x : 10 +>x : number break; } diff --git a/tests/baselines/reference/sourceMapValidationWhile.types b/tests/baselines/reference/sourceMapValidationWhile.types index 8769d98ef256c..71b50d86736cc 100644 --- a/tests/baselines/reference/sourceMapValidationWhile.types +++ b/tests/baselines/reference/sourceMapValidationWhile.types @@ -10,7 +10,7 @@ while (a == 10) { a++; >a++ : number ->a : 10 +>a : number } while (a == 10) >a == 10 : boolean @@ -19,5 +19,5 @@ while (a == 10) { a++; >a++ : number ->a : 10 +>a : number } diff --git a/tests/baselines/reference/superSymbolIndexedAccess3.errors.txt b/tests/baselines/reference/superSymbolIndexedAccess3.errors.txt index 1cac31dec4029..a7011e669104c 100644 --- a/tests/baselines/reference/superSymbolIndexedAccess3.errors.txt +++ b/tests/baselines/reference/superSymbolIndexedAccess3.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess3.ts(11,16): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess3.ts(11,22): error TS2538: Type 'typeof Bar' cannot be used as an index type. ==== tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess3.ts (1 errors) ==== @@ -13,7 +13,7 @@ tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess class Bar extends Foo { [symbol]() { return super[Bar](); - ~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~ +!!! error TS2538: Type 'typeof Bar' cannot be used as an index type. } } \ No newline at end of file diff --git a/tests/baselines/reference/symbolProperty53.errors.txt b/tests/baselines/reference/symbolProperty53.errors.txt index 03002cd92b28f..faea841358707 100644 --- a/tests/baselines/reference/symbolProperty53.errors.txt +++ b/tests/baselines/reference/symbolProperty53.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/Symbols/symbolProperty53.ts(2,5): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -tests/cases/conformance/es6/Symbols/symbolProperty53.ts(5,1): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/conformance/es6/Symbols/symbolProperty53.ts(5,5): error TS2538: Type '(key: string) => symbol' cannot be used as an index type. ==== tests/cases/conformance/es6/Symbols/symbolProperty53.ts (2 errors) ==== @@ -10,5 +10,5 @@ tests/cases/conformance/es6/Symbols/symbolProperty53.ts(5,1): error TS2342: An i }; obj[Symbol.for]; - ~~~~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. \ No newline at end of file + ~~~~~~~~~~ +!!! error TS2538: Type '(key: string) => symbol' cannot be used as an index type. \ No newline at end of file diff --git a/tests/baselines/reference/unaryOperatorsInStrictMode.errors.txt b/tests/baselines/reference/unaryOperatorsInStrictMode.errors.txt index 53263e7c2e179..35963c058795b 100644 --- a/tests/baselines/reference/unaryOperatorsInStrictMode.errors.txt +++ b/tests/baselines/reference/unaryOperatorsInStrictMode.errors.txt @@ -1,15 +1,15 @@ tests/cases/compiler/unaryOperatorsInStrictMode.ts(3,3): error TS1100: Invalid use of 'eval' in strict mode. -tests/cases/compiler/unaryOperatorsInStrictMode.ts(3,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/compiler/unaryOperatorsInStrictMode.ts(3,3): error TS2539: Cannot assign to 'eval' because it is not a variable. tests/cases/compiler/unaryOperatorsInStrictMode.ts(4,3): error TS1100: Invalid use of 'eval' in strict mode. -tests/cases/compiler/unaryOperatorsInStrictMode.ts(4,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/compiler/unaryOperatorsInStrictMode.ts(4,3): error TS2539: Cannot assign to 'eval' because it is not a variable. tests/cases/compiler/unaryOperatorsInStrictMode.ts(5,3): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/unaryOperatorsInStrictMode.ts(5,3): error TS2304: Cannot find name 'arguments'. tests/cases/compiler/unaryOperatorsInStrictMode.ts(6,3): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/unaryOperatorsInStrictMode.ts(6,3): error TS2304: Cannot find name 'arguments'. tests/cases/compiler/unaryOperatorsInStrictMode.ts(7,1): error TS1100: Invalid use of 'eval' in strict mode. -tests/cases/compiler/unaryOperatorsInStrictMode.ts(7,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/compiler/unaryOperatorsInStrictMode.ts(7,1): error TS2539: Cannot assign to 'eval' because it is not a variable. tests/cases/compiler/unaryOperatorsInStrictMode.ts(8,1): error TS1100: Invalid use of 'eval' in strict mode. -tests/cases/compiler/unaryOperatorsInStrictMode.ts(8,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/compiler/unaryOperatorsInStrictMode.ts(8,1): error TS2539: Cannot assign to 'eval' because it is not a variable. tests/cases/compiler/unaryOperatorsInStrictMode.ts(9,1): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/unaryOperatorsInStrictMode.ts(9,1): error TS2304: Cannot find name 'arguments'. tests/cases/compiler/unaryOperatorsInStrictMode.ts(10,1): error TS1100: Invalid use of 'arguments' in strict mode. @@ -23,12 +23,12 @@ tests/cases/compiler/unaryOperatorsInStrictMode.ts(10,1): error TS2304: Cannot f ~~~~ !!! error TS1100: Invalid use of 'eval' in strict mode. ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. --eval; ~~~~ !!! error TS1100: Invalid use of 'eval' in strict mode. ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. ++arguments; ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. @@ -43,12 +43,12 @@ tests/cases/compiler/unaryOperatorsInStrictMode.ts(10,1): error TS2304: Cannot f ~~~~ !!! error TS1100: Invalid use of 'eval' in strict mode. ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. eval--; ~~~~ !!! error TS1100: Invalid use of 'eval' in strict mode. ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. arguments++; ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. diff --git a/tests/baselines/reference/unionTypeReadonly.errors.txt b/tests/baselines/reference/unionTypeReadonly.errors.txt index ec660fc3a811f..8248431a93211 100644 --- a/tests/baselines/reference/unionTypeReadonly.errors.txt +++ b/tests/baselines/reference/unionTypeReadonly.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/types/union/unionTypeReadonly.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/union/unionTypeReadonly.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/union/unionTypeReadonly.ts(21,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/union/unionTypeReadonly.ts(23,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/conformance/types/union/unionTypeReadonly.ts(17,6): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. +tests/cases/conformance/types/union/unionTypeReadonly.ts(19,11): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. +tests/cases/conformance/types/union/unionTypeReadonly.ts(21,9): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. +tests/cases/conformance/types/union/unionTypeReadonly.ts(23,15): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. tests/cases/conformance/types/union/unionTypeReadonly.ts(25,15): error TS2339: Property 'value' does not exist on type 'Base | DifferentName'. Property 'value' does not exist on type 'DifferentName'. @@ -24,20 +24,20 @@ tests/cases/conformance/types/union/unionTypeReadonly.ts(25,15): error TS2339: P } let base: Base; base.value = 12 // error, lhs can't be a readonly property - ~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. let identical: Base | Identical; identical.value = 12; // error, lhs can't be a readonly property - ~~~~~~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. let mutable: Base | Mutable; mutable.value = 12; // error, lhs can't be a readonly property - ~~~~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. let differentType: Base | DifferentType; differentType.value = 12; // error, lhs can't be a readonly property - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. let differentName: Base | DifferentName; differentName.value = 12; // error, property 'value' doesn't exist ~~~~~ diff --git a/tests/baselines/reference/validNullAssignments.errors.txt b/tests/baselines/reference/validNullAssignments.errors.txt index 1fcebdcbaa9a1..ae3b0695c9d68 100644 --- a/tests/baselines/reference/validNullAssignments.errors.txt +++ b/tests/baselines/reference/validNullAssignments.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/types/primitives/null/validNullAssignments.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/primitives/null/validNullAssignments.ts(15,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/null/validNullAssignments.ts(10,3): error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. +tests/cases/conformance/types/primitives/null/validNullAssignments.ts(15,1): error TS2539: Cannot assign to 'C' because it is not a variable. tests/cases/conformance/types/primitives/null/validNullAssignments.ts(20,1): error TS2693: 'I' only refers to a type, but is being used as a value here. -tests/cases/conformance/types/primitives/null/validNullAssignments.ts(23,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/null/validNullAssignments.ts(23,1): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): error TS2539: Cannot assign to 'i' because it is not a variable. ==== tests/cases/conformance/types/primitives/null/validNullAssignments.ts (5 errors) ==== @@ -16,15 +16,15 @@ tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): err enum E { A } E.A = null; // error - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. class C { foo: string } var f: C; f = null; // ok C = null; // error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. interface I { foo: string } var g: I; @@ -36,7 +36,7 @@ tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): err module M { export var x = 1; } M = null; // error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. var h: { f(): void } = null; @@ -45,4 +45,4 @@ tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): err } i = null; // error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2539: Cannot assign to 'i' because it is not a variable. \ No newline at end of file diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts new file mode 100644 index 0000000000000..b63386a68a31e --- /dev/null +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts @@ -0,0 +1,167 @@ +// @declaration: true + +class Shape { + name: string; + width: number; + height: number; + visible: boolean; +} + +class Item { + name: string; + price: number; +} + +class Options { + visible: "yes" | "no"; +} + +type Dictionary = { [x: string]: T }; + +const enum E { A, B, C } + +type K00 = keyof any; // string | number +type K01 = keyof string; // number | "toString" | "charAt" | ... +type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ... +type K03 = keyof boolean; // "valueOf" +type K04 = keyof void; // never +type K05 = keyof undefined; // never +type K06 = keyof null; // never +type K07 = keyof never; // never + +type K10 = keyof Shape; // "name" | "width" | "height" | "visible" +type K11 = keyof Shape[]; // number | "length" | "toString" | ... +type K12 = keyof Dictionary; // string | number +type K13 = keyof {}; // never +type K14 = keyof Object; // "constructor" | "toString" | ... +type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ... +type K16 = keyof [string, number]; // number | "0" | "1" | "length" | "toString" | ... +type K17 = keyof (Shape | Item); // "name" +type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | "price" + +type KeyOf = keyof T; + +type K20 = KeyOf; // "name" | "width" | "height" | "visible" +type K21 = KeyOf>; // string | number + +type NAME = "name"; +type WIDTH_OR_HEIGHT = "width" | "height"; + +type Q10 = Shape["name"]; // string +type Q11 = Shape["width" | "height"]; // number +type Q12 = Shape["name" | "visible"]; // string | boolean + +type Q20 = Shape[NAME]; // string +type Q21 = Shape[WIDTH_OR_HEIGHT]; // number + +type Q30 = [string, number][0]; // string +type Q31 = [string, number][1]; // number +type Q32 = [string, number][2]; // string | number +type Q33 = [string, number][E.A]; // string +type Q34 = [string, number][E.B]; // number +type Q35 = [string, number][E.C]; // string | number +type Q36 = [string, number]["0"]; // string +type Q37 = [string, number]["1"]; // string + +type Q40 = (Shape | Options)["visible"]; // boolean | "yes" | "no" +type Q41 = (Shape & Options)["visible"]; // true & "yes" | true & "no" | false & "yes" | false & "no" + +type Q50 = Dictionary["howdy"]; // Shape +type Q51 = Dictionary[123]; // Shape +type Q52 = Dictionary[E.B]; // Shape + +declare let cond: boolean; + +function getProperty(obj: T, key: K) { + return obj[key]; +} + +function setProperty(obj: T, key: K, value: T[K]) { + obj[key] = value; +} + +function f10(shape: Shape) { + let name = getProperty(shape, "name"); // string + let widthOrHeight = getProperty(shape, cond ? "width" : "height"); // number + let nameOrVisible = getProperty(shape, cond ? "name" : "visible"); // string | boolean + setProperty(shape, "name", "rectangle"); + setProperty(shape, cond ? "width" : "height", 10); + setProperty(shape, cond ? "name" : "visible", true); // Technically not safe +} + +function f11(a: Shape[]) { + let len = getProperty(a, "length"); // number + let shape = getProperty(a, 1000); // Shape + setProperty(a, 1000, getProperty(a, 1001)); +} + +function f12(t: [Shape, boolean]) { + let len = getProperty(t, "length"); + let s1 = getProperty(t, 0); // Shape + let s2 = getProperty(t, "0"); // Shape + let b1 = getProperty(t, 1); // boolean + let b2 = getProperty(t, "1"); // boolean + let x1 = getProperty(t, 2); // Shape | boolean +} + +function f13(foo: any, bar: any) { + let x = getProperty(foo, "x"); // any + let y = getProperty(foo, 100); // any + let z = getProperty(foo, bar); // any +} + +class Component { + props: PropType; + getProperty(key: K) { + return this.props[key]; + } + setProperty(key: K, value: PropType[K]) { + this.props[key] = value; + } +} + +function f20(component: Component) { + let name = component.getProperty("name"); // string + let widthOrHeight = component.getProperty(cond ? "width" : "height"); // number + let nameOrVisible = component.getProperty(cond ? "name" : "visible"); // string | boolean + component.setProperty("name", "rectangle"); + component.setProperty(cond ? "width" : "height", 10) + component.setProperty(cond ? "name" : "visible", true); // Technically not safe +} + +function pluck(array: T[], key: K) { + return array.map(x => x[key]); +} + +function f30(shapes: Shape[]) { + let names = pluck(shapes, "name"); // string[] + let widths = pluck(shapes, "width"); // number[] + let nameOrVisibles = pluck(shapes, cond ? "name" : "visible"); // (string | boolean)[] +} + +function f31(key: K) { + const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; + return shape[key]; // Shape[K] +} + +function f32(key: K) { + const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; + return shape[key]; // Shape[K] +} + +class C { + public x: string; + protected y: string; + private z: string; +} + +// Indexed access expressions have always permitted access to private and protected members. +// For consistency we also permit such access in indexed access types. +function f40(c: C) { + type X = C["x"]; + type Y = C["y"]; + type Z = C["z"]; + let x: X = c["x"]; + let y: Y = c["y"]; + let z: Z = c["z"]; +} \ No newline at end of file diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts new file mode 100644 index 0000000000000..bc2ddc31a1920 --- /dev/null +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts @@ -0,0 +1,68 @@ +class Shape { + name: string; + width: number; + height: number; + visible: boolean; +} + +type Dictionary = { [x: string]: T }; + +type T00 = keyof K0; // Error + +type T01 = keyof Object; +type T02 = keyof keyof Object; +type T03 = keyof keyof keyof Object; +type T04 = keyof keyof keyof keyof Object; +type T05 = keyof keyof keyof keyof keyof Object; +type T06 = keyof keyof keyof keyof keyof keyof Object; + +type T10 = Shape["name"]; +type T11 = Shape["foo"]; // Error +type T12 = Shape["name" | "foo"]; // Error +type T13 = Shape[any]; // Error +type T14 = Shape[string]; // Error +type T15 = Shape[number]; // Error +type T16 = Shape[boolean]; // Error +type T17 = Shape[void]; // Error +type T18 = Shape[undefined]; // Error +type T19 = Shape[{ x: string }]; // Error +type T20 = Shape[string | number]; // Error +type T21 = Shape[string & number]; // Error +type T22 = Shape[string | boolean]; // Error + +type T30 = string[]["length"]; +type T31 = string[][number]; +type T32 = string[][string]; // Error +type T33 = string[][boolean]; // Error + +type T40 = Dictionary[any]; +type T41 = Dictionary[number]; +type T42 = Dictionary[string]; +type T43 = Dictionary[boolean]; // Error + +type T50 = any[any]; +type T51 = any[number]; +type T52 = any[string]; +type T53 = any[boolean]; // Error + +type T60 = {}["toString"]; +type T61 = []["toString"]; + +declare let cond: boolean; + +function getProperty(obj: T, key: K) { + return obj[key]; +} + +function setProperty(obj: T, key: K, value: T[K]) { + obj[key] = value; +} + +function f10(shape: Shape) { + let x1 = getProperty(shape, "name"); + let x2 = getProperty(shape, "size"); // Error + let x3 = getProperty(shape, cond ? "name" : "size"); // Error + setProperty(shape, "name", "rectangle"); + setProperty(shape, "size", 10); // Error + setProperty(shape, cond ? "name" : "size", 10); // Error +} \ No newline at end of file