diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4ea8c71e0548a..0a97e1229eca6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -134,6 +134,8 @@ namespace ts { const anySignature = createSignature(undefined, undefined, emptyArray, anyType, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false); const unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false); + const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true); + const globals: SymbolTable = {}; let globalESSymbolConstructorSymbol: Symbol; @@ -143,6 +145,7 @@ namespace ts { let globalObjectType: ObjectType; let globalFunctionType: ObjectType; let globalArrayType: GenericType; + let globalReadonlyArrayType: GenericType; let globalStringType: ObjectType; let globalNumberType: ObjectType; let globalBooleanType: ObjectType; @@ -154,6 +157,7 @@ namespace ts { let globalIterableIteratorType: GenericType; let anyArrayType: Type; + let anyReadonlyArrayType: Type; let getGlobalClassDecoratorType: () => ObjectType; let getGlobalParameterDecoratorType: () => ObjectType; let getGlobalPropertyDecoratorType: () => ObjectType; @@ -1382,19 +1386,19 @@ namespace ts { return result || emptyArray; } - function setObjectTypeMembers(type: ObjectType, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexType: Type, numberIndexType: Type): ResolvedType { + function setObjectTypeMembers(type: ObjectType, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexInfo: IndexInfo, numberIndexInfo: IndexInfo): ResolvedType { (type).members = members; (type).properties = getNamedMembers(members); (type).callSignatures = callSignatures; (type).constructSignatures = constructSignatures; - if (stringIndexType) (type).stringIndexType = stringIndexType; - if (numberIndexType) (type).numberIndexType = numberIndexType; + if (stringIndexInfo) (type).stringIndexInfo = stringIndexInfo; + if (numberIndexInfo) (type).numberIndexInfo = numberIndexInfo; return type; } - function createAnonymousType(symbol: Symbol, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexType: Type, numberIndexType: Type): ResolvedType { + function createAnonymousType(symbol: Symbol, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexInfo: IndexInfo, numberIndexInfo: IndexInfo): ResolvedType { return setObjectTypeMembers(createObjectType(TypeFlags.Anonymous, symbol), - members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } function forEachSymbolTableInScope(enclosingDeclaration: Node, callback: (symbolTable: SymbolTable) => T): T { @@ -2022,20 +2026,40 @@ namespace ts { buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value, SymbolFormatFlags.None, typeFormatFlags); } - function getIndexerParameterName(type: ObjectType, indexKind: IndexKind, fallbackName: string): string { - const declaration = getIndexDeclarationOfSymbol(type.symbol, indexKind); - if (!declaration) { - // declaration might not be found if indexer was added from the contextual type. - // in this case use fallback name - return fallbackName; + function writeIndexSignature(info: IndexInfo, keyword: SyntaxKind) { + if (info) { + if (info.isReadonly) { + writeKeyword(writer, SyntaxKind.ReadonlyKeyword); + writeSpace(writer); + } + writePunctuation(writer, SyntaxKind.OpenBracketToken); + writer.writeParameter(info.declaration ? declarationNameToString(info.declaration.parameters[0].name) : "x"); + writePunctuation(writer, SyntaxKind.ColonToken); + writeSpace(writer); + writeKeyword(writer, keyword); + writePunctuation(writer, SyntaxKind.CloseBracketToken); + writePunctuation(writer, SyntaxKind.ColonToken); + writeSpace(writer); + writeType(info.type, TypeFormatFlags.None); + writePunctuation(writer, SyntaxKind.SemicolonToken); + writer.writeLine(); + } + } + + function writePropertyWithModifiers(prop: Symbol) { + if (isReadonlySymbol(prop)) { + writeKeyword(writer, SyntaxKind.ReadonlyKeyword); + writeSpace(writer); + } + buildSymbolDisplay(prop, writer); + if (prop.flags & SymbolFlags.Optional) { + writePunctuation(writer, SyntaxKind.QuestionToken); } - Debug.assert(declaration.parameters.length !== 0); - return declarationNameToString(declaration.parameters[0].name); } function writeLiteralType(type: ObjectType, flags: TypeFormatFlags) { const resolved = resolveStructuredTypeMembers(type); - if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) { + if (!resolved.properties.length && !resolved.stringIndexInfo && !resolved.numberIndexInfo) { if (!resolved.callSignatures.length && !resolved.constructSignatures.length) { writePunctuation(writer, SyntaxKind.OpenBraceToken); writePunctuation(writer, SyntaxKind.CloseBraceToken); @@ -2081,53 +2105,21 @@ namespace ts { writePunctuation(writer, SyntaxKind.SemicolonToken); writer.writeLine(); } - if (resolved.stringIndexType) { - // [x: string]: - writePunctuation(writer, SyntaxKind.OpenBracketToken); - writer.writeParameter(getIndexerParameterName(resolved, IndexKind.String, /*fallbackName*/"x")); - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeKeyword(writer, SyntaxKind.StringKeyword); - writePunctuation(writer, SyntaxKind.CloseBracketToken); - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeType(resolved.stringIndexType, TypeFormatFlags.None); - writePunctuation(writer, SyntaxKind.SemicolonToken); - writer.writeLine(); - } - if (resolved.numberIndexType) { - // [x: number]: - writePunctuation(writer, SyntaxKind.OpenBracketToken); - writer.writeParameter(getIndexerParameterName(resolved, IndexKind.Number, /*fallbackName*/"x")); - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeKeyword(writer, SyntaxKind.NumberKeyword); - writePunctuation(writer, SyntaxKind.CloseBracketToken); - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeType(resolved.numberIndexType, TypeFormatFlags.None); - writePunctuation(writer, SyntaxKind.SemicolonToken); - writer.writeLine(); - } + writeIndexSignature(resolved.stringIndexInfo, SyntaxKind.StringKeyword); + writeIndexSignature(resolved.numberIndexInfo, SyntaxKind.NumberKeyword); for (const p of resolved.properties) { const t = getTypeOfSymbol(p); if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(t).length) { const signatures = getSignaturesOfType(t, SignatureKind.Call); for (const signature of signatures) { - buildSymbolDisplay(p, writer); - if (p.flags & SymbolFlags.Optional) { - writePunctuation(writer, SyntaxKind.QuestionToken); - } + writePropertyWithModifiers(p); buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, /*kind*/ undefined, symbolStack); writePunctuation(writer, SyntaxKind.SemicolonToken); writer.writeLine(); } } else { - buildSymbolDisplay(p, writer); - if (p.flags & SymbolFlags.Optional) { - writePunctuation(writer, SyntaxKind.QuestionToken); - } + writePropertyWithModifiers(p); writePunctuation(writer, SyntaxKind.ColonToken); writeSpace(writer); writeType(t, TypeFormatFlags.None); @@ -3463,8 +3455,8 @@ namespace ts { (type).declaredProperties = getNamedMembers(symbol.members); (type).declaredCallSignatures = getSignaturesOfSymbol(symbol.members["__call"]); (type).declaredConstructSignatures = getSignaturesOfSymbol(symbol.members["__new"]); - (type).declaredStringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String); - (type).declaredNumberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number); + (type).declaredStringIndexInfo = getIndexInfoOfSymbol(symbol, IndexKind.String); + (type).declaredNumberIndexInfo = getIndexInfoOfSymbol(symbol, IndexKind.Number); } return type; } @@ -3482,15 +3474,15 @@ namespace ts { let members = source.symbol.members; let callSignatures = source.declaredCallSignatures; let constructSignatures = source.declaredConstructSignatures; - let stringIndexType = source.declaredStringIndexType; - let numberIndexType = source.declaredNumberIndexType; + let stringIndexInfo = source.declaredStringIndexInfo; + let numberIndexInfo = source.declaredNumberIndexInfo; if (!rangeEquals(typeParameters, typeArguments, 0, typeParameters.length)) { mapper = createTypeMapper(typeParameters, typeArguments); members = createInstantiatedSymbolTable(source.declaredProperties, mapper, /*mappingThisOnly*/ typeParameters.length === 1); callSignatures = instantiateList(source.declaredCallSignatures, mapper, instantiateSignature); constructSignatures = instantiateList(source.declaredConstructSignatures, mapper, instantiateSignature); - stringIndexType = instantiateType(source.declaredStringIndexType, mapper); - numberIndexType = instantiateType(source.declaredNumberIndexType, mapper); + stringIndexInfo = instantiateIndexInfo(source.declaredStringIndexInfo, mapper); + numberIndexInfo = instantiateIndexInfo(source.declaredNumberIndexInfo, mapper); } const baseTypes = getBaseTypes(source); if (baseTypes.length) { @@ -3503,11 +3495,11 @@ namespace ts { addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); callSignatures = concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Call)); constructSignatures = concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Construct)); - stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, IndexKind.String); - numberIndexType = numberIndexType || getIndexTypeOfType(instantiatedBaseType, IndexKind.Number); + stringIndexInfo = stringIndexInfo || getIndexInfoOfType(instantiatedBaseType, IndexKind.String); + numberIndexInfo = numberIndexInfo || getIndexInfoOfType(instantiatedBaseType, IndexKind.Number); } } - setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } function resolveClassOrInterfaceMembers(type: InterfaceType): void { @@ -3578,7 +3570,7 @@ namespace ts { const arrayType = resolveStructuredTypeMembers(createTypeFromGenericGlobalType(globalArrayType, [arrayElementType, type])); const members = createTupleTypeMemberSymbols(type.elementTypes); addInheritedMembers(members, arrayType.properties); - setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType); + setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexInfo, arrayType.numberIndexInfo); } function findMatchingSignature(signatureList: Signature[], signature: Signature, partialMatch: boolean, ignoreReturnTypes: boolean): Signature { @@ -3646,16 +3638,18 @@ namespace ts { return result || emptyArray; } - function getUnionIndexType(types: Type[], kind: IndexKind): Type { + function getUnionIndexInfo(types: Type[], kind: IndexKind): IndexInfo { const indexTypes: Type[] = []; + let isAnyReadonly = false; for (const type of types) { - const indexType = getIndexTypeOfType(type, kind); - if (!indexType) { + const indexInfo = getIndexInfoOfType(type, kind); + if (!indexInfo) { return undefined; } - indexTypes.push(indexType); + indexTypes.push(indexInfo.type); + isAnyReadonly = isAnyReadonly || indexInfo.isReadonly; } - return getUnionType(indexTypes); + return createIndexInfo(getUnionType(indexTypes), isAnyReadonly); } function resolveUnionTypeMembers(type: UnionType) { @@ -3663,29 +3657,34 @@ namespace ts { // type use getPropertiesOfType (only the language service uses this). const callSignatures = getUnionSignatures(type.types, SignatureKind.Call); const constructSignatures = getUnionSignatures(type.types, SignatureKind.Construct); - const stringIndexType = getUnionIndexType(type.types, IndexKind.String); - const numberIndexType = getUnionIndexType(type.types, IndexKind.Number); - setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType); + const stringIndexInfo = getUnionIndexInfo(type.types, IndexKind.String); + const numberIndexInfo = getUnionIndexInfo(type.types, IndexKind.Number); + setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } function intersectTypes(type1: Type, type2: Type): Type { return !type1 ? type2 : !type2 ? type1 : getIntersectionType([type1, type2]); } + function intersectIndexInfos(info1: IndexInfo, info2: IndexInfo): IndexInfo { + return !info1 ? info2 : !info2 ? info1 : createIndexInfo( + getIntersectionType([info1.type, info2.type]), info1.isReadonly && info2.isReadonly); + } + function resolveIntersectionTypeMembers(type: IntersectionType) { // The members and properties collections are empty for intersection types. To get all properties of an // intersection type use getPropertiesOfType (only the language service uses this). let callSignatures: Signature[] = emptyArray; let constructSignatures: Signature[] = emptyArray; - let stringIndexType: Type = undefined; - let numberIndexType: Type = undefined; + let stringIndexInfo: IndexInfo = undefined; + let numberIndexInfo: IndexInfo = undefined; for (const t of type.types) { callSignatures = concatenate(callSignatures, getSignaturesOfType(t, SignatureKind.Call)); constructSignatures = concatenate(constructSignatures, getSignaturesOfType(t, SignatureKind.Construct)); - stringIndexType = intersectTypes(stringIndexType, getIndexTypeOfType(t, IndexKind.String)); - numberIndexType = intersectTypes(numberIndexType, getIndexTypeOfType(t, IndexKind.Number)); + stringIndexInfo = intersectIndexInfos(stringIndexInfo, getIndexInfoOfType(t, IndexKind.String)); + numberIndexInfo = intersectIndexInfos(numberIndexInfo, getIndexInfoOfType(t, IndexKind.Number)); } - setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType); + setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } function resolveAnonymousTypeMembers(type: AnonymousType) { @@ -3694,17 +3693,17 @@ namespace ts { const members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false); const callSignatures = instantiateList(getSignaturesOfType(type.target, SignatureKind.Call), type.mapper, instantiateSignature); const constructSignatures = instantiateList(getSignaturesOfType(type.target, SignatureKind.Construct), type.mapper, instantiateSignature); - const stringIndexType = instantiateType(getIndexTypeOfType(type.target, IndexKind.String), type.mapper); - const numberIndexType = instantiateType(getIndexTypeOfType(type.target, IndexKind.Number), type.mapper); - setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + const stringIndexInfo = instantiateIndexInfo(getIndexInfoOfType(type.target, IndexKind.String), type.mapper); + const numberIndexInfo = instantiateIndexInfo(getIndexInfoOfType(type.target, IndexKind.Number), type.mapper); + setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } else if (symbol.flags & SymbolFlags.TypeLiteral) { const members = symbol.members; const callSignatures = getSignaturesOfSymbol(members["__call"]); const constructSignatures = getSignaturesOfSymbol(members["__new"]); - const stringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String); - const numberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number); - setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + const stringIndexInfo = getIndexInfoOfSymbol(symbol, IndexKind.String); + const numberIndexInfo = getIndexInfoOfSymbol(symbol, IndexKind.Number); + setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } else { // Combinations of function, class, enum and module @@ -3725,8 +3724,8 @@ namespace ts { addInheritedMembers(members, getPropertiesOfObjectType(baseConstructorType)); } } - const numberIndexType = (symbol.flags & SymbolFlags.Enum) ? stringType : undefined; - setObjectTypeMembers(type, members, emptyArray, constructSignatures, undefined, numberIndexType); + const numberIndexInfo = symbol.flags & SymbolFlags.Enum ? enumNumberIndexInfo : undefined; + setObjectTypeMembers(type, members, emptyArray, constructSignatures, undefined, numberIndexInfo); // We resolve the members before computing the signatures because a signature may use // typeof with a qualified name expression that circularly references the type we are // in the process of resolving (see issue #6072). The temporarily empty signature list @@ -3945,13 +3944,25 @@ namespace ts { function getSignaturesOfType(type: Type, kind: SignatureKind): Signature[] { return getSignaturesOfStructuredType(getApparentType(type), kind); } - function getIndexTypeOfStructuredType(type: Type, kind: IndexKind): Type { + + function getIndexInfoOfStructuredType(type: Type, kind: IndexKind): IndexInfo { if (type.flags & TypeFlags.StructuredType) { const resolved = resolveStructuredTypeMembers(type); - return kind === IndexKind.String ? resolved.stringIndexType : resolved.numberIndexType; + return kind === IndexKind.String ? resolved.stringIndexInfo : resolved.numberIndexInfo; } } + function getIndexTypeOfStructuredType(type: Type, kind: IndexKind): Type { + const info = getIndexInfoOfStructuredType(type, kind); + return info && info.type; + } + + // Return the indexing info of the given kind in the given type. Creates synthetic union index types when necessary and + // maps primitive types and type parameters are to their apparent types. + function getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo { + return getIndexInfoOfStructuredType(getApparentType(type), kind); + } + // Return the index type of the given kind in the given type. Creates synthetic union index types when necessary and // maps primitive types and type parameters are to their apparent types. function getIndexTypeOfType(type: Type, kind: IndexKind): Type { @@ -4272,11 +4283,17 @@ namespace ts { return undefined; } - function getIndexTypeOfSymbol(symbol: Symbol, kind: IndexKind): Type { + function createIndexInfo(type: Type, isReadonly: boolean, declaration?: SignatureDeclaration): IndexInfo { + return { type, isReadonly, declaration }; + } + + function getIndexInfoOfSymbol(symbol: Symbol, kind: IndexKind): IndexInfo { const declaration = getIndexDeclarationOfSymbol(symbol, kind); - return declaration - ? declaration.type ? getTypeFromTypeNode(declaration.type) : anyType - : undefined; + if (declaration) { + return createIndexInfo(declaration.type ? getTypeFromTypeNode(declaration.type) : anyType, + (declaration.flags & NodeFlags.Readonly) !== 0, declaration); + } + return undefined; } function getConstraintDeclaration(type: TypeParameter) { @@ -5112,6 +5129,10 @@ namespace ts { return type; } + function instantiateIndexInfo(info: IndexInfo, mapper: TypeMapper): IndexInfo { + return info && createIndexInfo(instantiateType(info.type, mapper), info.isReadonly, info.declaration); + } + // Returns true if the given expression contains (at any level of nesting) a function or arrow expression // that is subject to contextual typing. function isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElement): boolean { @@ -5537,7 +5558,7 @@ namespace ts { if (type.flags & TypeFlags.ObjectType) { const resolved = resolveStructuredTypeMembers(type); if (relation === assignableRelation && (type === globalObjectType || resolved.properties.length === 0) || - resolved.stringIndexType || resolved.numberIndexType || getPropertyOfType(type, name)) { + resolved.stringIndexInfo || resolved.numberIndexInfo || getPropertyOfType(type, name)) { return true; } } @@ -5921,21 +5942,21 @@ namespace ts { if (relation === identityRelation) { return indexTypesIdenticalTo(IndexKind.String, source, target); } - const targetType = getIndexTypeOfType(target, IndexKind.String); - if (targetType) { - if ((targetType.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) { + const targetInfo = getIndexInfoOfType(target, IndexKind.String); + if (targetInfo) { + if ((targetInfo.type.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) { // non-primitive assignment to any is always allowed, eg // `var x: { [index: string]: any } = { property: 12 };` return Ternary.True; } - const sourceType = getIndexTypeOfType(source, IndexKind.String); - if (!sourceType) { + const sourceInfo = getIndexInfoOfType(source, IndexKind.String); + if (!sourceInfo) { if (reportErrors) { reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } return Ternary.False; } - const related = isRelatedTo(sourceType, targetType, reportErrors); + const related = isRelatedTo(sourceInfo.type, targetInfo.type, reportErrors); if (!related) { if (reportErrors) { reportError(Diagnostics.Index_signatures_are_incompatible); @@ -5951,28 +5972,29 @@ namespace ts { if (relation === identityRelation) { return indexTypesIdenticalTo(IndexKind.Number, source, target); } - const targetType = getIndexTypeOfType(target, IndexKind.Number); - if (targetType) { - if ((targetType.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) { + const targetInfo = getIndexInfoOfType(target, IndexKind.Number); + if (targetInfo) { + if ((targetInfo.type.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) { // non-primitive assignment to any is always allowed, eg // `var x: { [index: number]: any } = { property: 12 };` return Ternary.True; } - const sourceStringType = getIndexTypeOfType(source, IndexKind.String); - const sourceNumberType = getIndexTypeOfType(source, IndexKind.Number); - if (!(sourceStringType || sourceNumberType)) { + const sourceStringInfo = getIndexInfoOfType(source, IndexKind.String); + const sourceNumberInfo = getIndexInfoOfType(source, IndexKind.Number); + if (!(sourceStringInfo || sourceNumberInfo)) { if (reportErrors) { reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } return Ternary.False; } let related: Ternary; - if (sourceStringType && sourceNumberType) { + if (sourceStringInfo && sourceNumberInfo) { // If we know for sure we're testing both string and numeric index types then only report errors from the second one - related = isRelatedTo(sourceStringType, targetType, /*reportErrors*/ false) || isRelatedTo(sourceNumberType, targetType, reportErrors); + related = isRelatedTo(sourceStringInfo.type, targetInfo.type, /*reportErrors*/ false) || + isRelatedTo(sourceNumberInfo.type, targetInfo.type, reportErrors); } else { - related = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); + related = isRelatedTo((sourceStringInfo || sourceNumberInfo).type, targetInfo.type, reportErrors); } if (!related) { if (reportErrors) { @@ -5986,13 +6008,13 @@ namespace ts { } function indexTypesIdenticalTo(indexKind: IndexKind, source: Type, target: Type): Ternary { - const targetType = getIndexTypeOfType(target, indexKind); - const sourceType = getIndexTypeOfType(source, indexKind); - if (!sourceType && !targetType) { + const targetInfo = getIndexInfoOfType(target, indexKind); + const sourceInfo = getIndexInfoOfType(source, indexKind); + if (!sourceInfo && !targetInfo) { return Ternary.True; } - if (sourceType && targetType) { - return isRelatedTo(sourceType, targetType); + if (sourceInfo && targetInfo && sourceInfo.isReadonly === targetInfo.isReadonly) { + return isRelatedTo(sourceInfo.type, targetInfo.type); } return Ternary.False; } @@ -6080,6 +6102,9 @@ namespace ts { return Ternary.False; } } + if (isReadonlySymbol(sourceProp) !== isReadonlySymbol(targetProp)) { + return Ternary.False; + } return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); } @@ -6203,8 +6228,10 @@ namespace ts { } function isArrayLikeType(type: Type): boolean { - // A type is array-like if it is not the undefined or null type and if it is assignable to any[] - return !(type.flags & (TypeFlags.Undefined | TypeFlags.Null)) && isTypeAssignableTo(type, anyArrayType); + // A type is array-like if it is a reference to the global Array or global ReadonlyArray type, + // or if it is not the undefined or null type and if it is assignable to ReadonlyArray + return type.flags & TypeFlags.Reference && ((type).target === globalArrayType || (type).target === globalReadonlyArrayType) || + !(type.flags & (TypeFlags.Undefined | TypeFlags.Null)) && isTypeAssignableTo(type, anyReadonlyArrayType); } function isTupleLikeType(type: Type): boolean { @@ -6233,8 +6260,8 @@ namespace ts { regularType.properties = (type).properties; regularType.callSignatures = (type).callSignatures; regularType.constructSignatures = (type).constructSignatures; - regularType.stringIndexType = (type).stringIndexType; - regularType.numberIndexType = (type).numberIndexType; + regularType.stringIndexInfo = (type).stringIndexInfo; + regularType.numberIndexInfo = (type).numberIndexInfo; (type).regularType = regularType; } return regularType; @@ -6259,11 +6286,11 @@ namespace ts { } members[p.name] = p; }); - let stringIndexType = getIndexTypeOfType(type, IndexKind.String); - let numberIndexType = getIndexTypeOfType(type, IndexKind.Number); - if (stringIndexType) stringIndexType = getWidenedType(stringIndexType); - if (numberIndexType) numberIndexType = getWidenedType(numberIndexType); - return createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); + const stringIndexInfo = getIndexInfoOfType(type, IndexKind.String); + const numberIndexInfo = getIndexInfoOfType(type, IndexKind.Number); + return createAnonymousType(type.symbol, members, emptyArray, emptyArray, + stringIndexInfo && createIndexInfo(getWidenedType(stringIndexInfo.type), stringIndexInfo.isReadonly), + numberIndexInfo && createIndexInfo(getWidenedType(numberIndexInfo.type), numberIndexInfo.isReadonly)); } function getWidenedType(type: Type): Type { @@ -7658,7 +7685,7 @@ namespace ts { // Return true if the given contextual type provides an index signature of the given kind function contextualTypeHasIndexSignature(type: Type, kind: IndexKind): boolean { - return !!(type.flags & TypeFlags.Union ? forEach((type).types, t => getIndexTypeOfStructuredType(t, kind)) : getIndexTypeOfStructuredType(type, kind)); + return !!(type.flags & TypeFlags.Union ? forEach((type).types, t => getIndexInfoOfStructuredType(t, kind)) : getIndexInfoOfStructuredType(type, kind)); } // In an object literal contextually typed by a type T, the contextual type of a property assignment is the type of @@ -8153,9 +8180,9 @@ namespace ts { } } - const stringIndexType = getIndexType(IndexKind.String); - const numberIndexType = getIndexType(IndexKind.Number); - const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); + const stringIndexInfo = getIndexInfo(IndexKind.String); + const numberIndexInfo = getIndexInfo(IndexKind.Number); + const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshObjectLiteral; result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags) | (patternWithComputedProperties ? TypeFlags.ObjectLiteralPatternWithComputedProperties : 0); if (inDestructuringPattern) { @@ -8163,7 +8190,7 @@ namespace ts { } return result; - function getIndexType(kind: IndexKind) { + function getIndexInfo(kind: IndexKind) { if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { const propTypes: Type[] = []; for (let i = 0; i < propertiesArray.length; i++) { @@ -8179,9 +8206,9 @@ namespace ts { } } } - const result = propTypes.length ? getUnionType(propTypes) : undefinedType; - typeFlags |= result.flags; - return result; + const unionType = propTypes.length ? getUnionType(propTypes) : undefinedType; + typeFlags |= unionType.flags; + return createIndexInfo(unionType, /*isReadonly*/ false); } return undefined; } @@ -8551,7 +8578,7 @@ namespace ts { return links.resolvedJsxType = getTypeOfSymbol(sym); } else if (links.jsxFlags & JsxFlags.IntrinsicIndexedElement) { - return links.resolvedJsxType = getIndexTypeOfSymbol(sym, IndexKind.String); + return links.resolvedJsxType = getIndexInfoOfSymbol(sym, IndexKind.String).type; } else { // Resolution failed, so we don't know @@ -8918,16 +8945,18 @@ namespace ts { // Try to use a number indexer. if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.NumberLike) || isForInVariableForNumericPropertyNames(node.argumentExpression)) { - const numberIndexType = getIndexTypeOfType(objectType, IndexKind.Number); - if (numberIndexType) { - return numberIndexType; + const numberIndexInfo = getIndexInfoOfType(objectType, IndexKind.Number); + if (numberIndexInfo) { + getNodeLinks(node).resolvedIndexInfo = numberIndexInfo; + return numberIndexInfo.type; } } // Try to use string indexing. - const stringIndexType = getIndexTypeOfType(objectType, IndexKind.String); - if (stringIndexType) { - return stringIndexType; + const stringIndexInfo = getIndexInfoOfType(objectType, IndexKind.String); + if (stringIndexInfo) { + getNodeLinks(node).resolvedIndexInfo = stringIndexInfo; + return stringIndexInfo.type; } // Fall back to any. @@ -9186,7 +9215,7 @@ namespace ts { if (type.flags & TypeFlags.ObjectType) { const resolved = resolveStructuredTypeMembers(type); if (resolved.callSignatures.length === 1 && resolved.constructSignatures.length === 0 && - resolved.properties.length === 0 && !resolved.stringIndexType && !resolved.numberIndexType) { + resolved.properties.length === 0 && !resolved.stringIndexInfo && !resolved.numberIndexInfo) { return resolved.callSignatures[0]; } } @@ -10559,81 +10588,78 @@ namespace ts { return true; } - function checkReferenceExpression(n: Node, invalidReferenceMessage: DiagnosticMessage, constantVariableMessage: DiagnosticMessage): boolean { - function findSymbol(n: Node): Symbol { - const symbol = getNodeLinks(n).resolvedSymbol; - // Because we got 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. - return symbol && getExportSymbolOfValueSymbolIfExported(symbol); - } - - function isReferenceOrErrorExpression(n: Node): boolean { - // TypeScript 1.0 spec (April 2014): - // Expressions are classified as values or references. - // References are the subset of expressions that are permitted as the target of an assignment. - // Specifically, references are combinations of identifiers(section 4.3), parentheses(section 4.7), - // and property accesses(section 4.10). - // All other expression constructs described in this chapter are classified as values. - switch (n.kind) { - case SyntaxKind.Identifier: { - const symbol = findSymbol(n); - // TypeScript 1.0 spec (April 2014): 4.3 - // An identifier expression that references a variable or parameter is classified as a reference. - // An identifier expression that references any other kind of entity is classified as a value(and therefore cannot be the target of an assignment). - return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & SymbolFlags.Variable) !== 0; - } - case SyntaxKind.PropertyAccessExpression: { - const symbol = findSymbol(n); - // TypeScript 1.0 spec (April 2014): 4.10 - // A property access expression is always classified as a reference. - // NOTE (not in spec): assignment to enum members should not be allowed - return !symbol || symbol === unknownSymbol || (symbol.flags & ~SymbolFlags.EnumMember) !== 0; - } - case SyntaxKind.ElementAccessExpression: - // old compiler doesn't check indexed access - return true; - case SyntaxKind.ParenthesizedExpression: - return isReferenceOrErrorExpression((n).expression); - default: - return false; + function isReadonlySymbol(symbol: Symbol): boolean { + // The following symbols are considered read-only: + // Properties with a 'readonly' modifier + // Variables declared with 'const' + // Get accessors without matching set accessors + // Enum members + return symbol.flags & SymbolFlags.Property && (getDeclarationFlagsFromSymbol(symbol) & NodeFlags.Readonly) !== 0 || + symbol.flags & SymbolFlags.Variable && (getDeclarationFlagsFromSymbol(symbol) & NodeFlags.Const) !== 0 || + symbol.flags & SymbolFlags.Accessor && !(symbol.flags & SymbolFlags.SetAccessor) || + (symbol.flags & SymbolFlags.EnumMember) !== 0; + } + + function isReferenceToReadonlyEntity(expr: Expression, symbol: Symbol): boolean { + if (isReadonlySymbol(symbol)) { + // Allow assignments to readonly properties within constructors of the same class declaration. + if (symbol.flags & SymbolFlags.Property && + (expr.kind === SyntaxKind.PropertyAccessExpression || expr.kind === SyntaxKind.ElementAccessExpression) && + (expr as PropertyAccessExpression | ElementAccessExpression).expression.kind === SyntaxKind.ThisKeyword) { + const func = getContainingFunction(expr); + return !(func && func.kind === SyntaxKind.Constructor && func.parent === symbol.valueDeclaration.parent); } + return true; } + return false; + } - function isConstVariableReference(n: Node): boolean { - switch (n.kind) { - case SyntaxKind.Identifier: - case SyntaxKind.PropertyAccessExpression: { - const symbol = findSymbol(n); - return symbol && (symbol.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & NodeFlags.Const) !== 0; - } - case SyntaxKind.ElementAccessExpression: { - const index = (n).argumentExpression; - const symbol = findSymbol((n).expression); - if (symbol && index && index.kind === SyntaxKind.StringLiteral) { - const name = (index).text; - const prop = getPropertyOfType(getTypeOfSymbol(symbol), name); - return prop && (prop.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(prop) & NodeFlags.Const) !== 0; - } - return false; + function isReferenceThroughNamespaceImport(expr: Expression): boolean { + if (expr.kind === SyntaxKind.PropertyAccessExpression || expr.kind === SyntaxKind.ElementAccessExpression) { + const node = skipParenthesizedNodes((expr as PropertyAccessExpression | ElementAccessExpression).expression); + if (node.kind === SyntaxKind.Identifier) { + const symbol = getNodeLinks(node).resolvedSymbol; + if (symbol.flags & SymbolFlags.Alias) { + const declaration = getDeclarationOfAliasSymbol(symbol); + return declaration && declaration.kind === SyntaxKind.NamespaceImport; } - case SyntaxKind.ParenthesizedExpression: - return isConstVariableReference((n).expression); - default: - return false; } } + return false; + } - if (!isReferenceOrErrorExpression(n)) { - error(n, invalidReferenceMessage); + function checkReferenceExpression(expr: Expression, invalidReferenceMessage: DiagnosticMessage, constantVariableMessage: DiagnosticMessage): boolean { + // References are combinations of identifiers, parentheses, and property accesses. + const node = skipParenthesizedNodes(expr); + if (node.kind !== SyntaxKind.Identifier && node.kind !== SyntaxKind.PropertyAccessExpression && node.kind !== SyntaxKind.ElementAccessExpression) { + error(expr, invalidReferenceMessage); return false; } - - if (isConstVariableReference(n)) { - error(n, constantVariableMessage); - 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; } @@ -10687,7 +10713,7 @@ namespace ts { // 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); + Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant_or_a_read_only_property); } return numberType; } @@ -10701,7 +10727,7 @@ namespace ts { // 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); + Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant_or_a_read_only_property); } return numberType; } @@ -10892,7 +10918,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)) { + 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)) { checkTypeAssignableTo(sourceType, targetType, target, /*headMessage*/ undefined); } return sourceType; @@ -11074,7 +11100,9 @@ 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); + 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) { // to avoid cascading errors check assignability only if 'isReference' check succeeded and no errors were reported @@ -13138,7 +13166,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_previously_defined_constant); + /*constantVariableMessage*/ Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_be_a_constant_or_a_read_only_property); // iteratedType will be undefined if the rightType was missing properties/signatures // required to get its iteratedType (like [Symbol.iterator] or next). This may be @@ -13185,7 +13213,8 @@ 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_previously_defined_constant); + 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); } } @@ -15908,6 +15937,10 @@ namespace ts { } anyArrayType = createArrayType(anyType); + + const symbol = getGlobalSymbol("ReadonlyArray", SymbolFlags.Type, /*diagnostic*/ undefined); + globalReadonlyArrayType = symbol && getTypeOfGlobalSymbol(symbol, /*arity*/ 1); + anyReadonlyArrayType = globalReadonlyArrayType ? createTypeFromGenericGlobalType(globalReadonlyArrayType, [anyType]) : anyArrayType; } function createInstantiatedPromiseLikeType(): ObjectType { @@ -15999,9 +16032,17 @@ namespace ts { return; } - let lastStatic: Node, lastPrivate: Node, lastProtected: Node, lastDeclare: Node, lastAsync: Node; + let lastStatic: Node, lastPrivate: Node, lastProtected: Node, lastDeclare: Node, lastAsync: Node, lastReadonly: Node; let flags = 0; for (const modifier of node.modifiers) { + if (modifier.kind !== SyntaxKind.ReadonlyKeyword) { + if (node.kind === SyntaxKind.PropertySignature || node.kind === SyntaxKind.MethodSignature) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_type_member, tokenToString(modifier.kind)); + } + if (node.kind === SyntaxKind.IndexSignature) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_an_index_signature, tokenToString(modifier.kind)); + } + } switch (modifier.kind) { case SyntaxKind.ConstKeyword: if (node.kind !== SyntaxKind.EnumDeclaration && node.parent.kind === SyntaxKind.ClassDeclaration) { @@ -16030,6 +16071,9 @@ namespace ts { else if (flags & NodeFlags.Static) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, text, "static"); } + else if (flags & NodeFlags.Readonly) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, text, "readonly"); + } else if (flags & NodeFlags.Async) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, text, "async"); } @@ -16051,6 +16095,9 @@ namespace ts { if (flags & NodeFlags.Static) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "static"); } + else if (flags & NodeFlags.Readonly) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "static", "readonly"); + } else if (flags & NodeFlags.Async) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "static", "async"); } @@ -16067,6 +16114,17 @@ namespace ts { lastStatic = modifier; break; + case SyntaxKind.ReadonlyKeyword: + if (flags & NodeFlags.Readonly) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "readonly"); + } + else if (node.kind !== SyntaxKind.PropertyDeclaration && node.kind !== SyntaxKind.PropertySignature && node.kind !== SyntaxKind.IndexSignature) { + return grammarErrorOnNode(modifier, Diagnostics.readonly_modifier_can_only_appear_on_a_property_declaration_or_index_signature); + } + flags |= NodeFlags.Readonly; + lastReadonly = modifier; + break; + case SyntaxKind.ExportKeyword: if (flags & NodeFlags.Export) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "export"); @@ -16163,6 +16221,9 @@ namespace ts { else if (flags & NodeFlags.Async) { return grammarErrorOnNode(lastAsync, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "async"); } + else if (flags & NodeFlags.Readonly) { + return grammarErrorOnNode(lastReadonly, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "readonly"); + } return; } else if ((node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration) && flags & NodeFlags.Ambient) { @@ -16308,15 +16369,9 @@ namespace ts { } } - function checkGrammarForIndexSignatureModifier(node: SignatureDeclaration): void { - if (node.flags & NodeFlags.Modifier) { - grammarErrorOnFirstToken(node, Diagnostics.Modifiers_not_permitted_on_index_signature_members); - } - } - function checkGrammarIndexSignature(node: SignatureDeclaration) { // Prevent cascading error by short-circuit - return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarIndexSignatureParameters(node) || checkGrammarForIndexSignatureModifier(node); + return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarIndexSignatureParameters(node); } function checkGrammarForAtLeastOneTypeArgument(node: Node, typeArguments: NodeArray): boolean { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 8fd40f7b42169..87de69bb4d55d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -67,6 +67,10 @@ "category": "Error", "code": 1023 }, + "'readonly' modifier can only appear on a property declaration or index signature.": { + "category": "Error", + "code": 1024 + }, "Accessibility modifier already seen.": { "category": "Error", "code": 1028 @@ -203,6 +207,14 @@ "category": "Error", "code": 1068 }, + "'{0}' modifier cannot appear on a type member.": { + "category": "Error", + "code": 1070 + }, + "'{0}' modifier cannot appear on an index signature.": { + "category": "Error", + "code": 1071 + }, "A '{0}' modifier cannot be used with an import declaration.": { "category": "Error", "code": 1079 @@ -423,10 +435,6 @@ "category": "Error", "code": 1144 }, - "Modifiers not permitted on index signature members.": { - "category": "Error", - "code": 1145 - }, "Declaration expected.": { "category": "Error", "code": 1146 @@ -1379,11 +1387,11 @@ "category": "Error", "code": 2448 }, - "The operand of an increment or decrement operator cannot be a constant.": { + "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.": { + "Left-hand side of assignment expression cannot be a constant or a read-only property.": { "category": "Error", "code": 2450 }, @@ -1515,11 +1523,11 @@ "category": "Error", "code": 2484 }, - "The left-hand side of a 'for...of' statement cannot be a previously defined constant.": { + "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 previously defined constant.": { + "The left-hand side of a 'for...in' statement cannot be a constant or a read-only property.": { "category": "Error", "code": 2486 }, diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index ecf64392a9a73..5b4c04ddd021a 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1172,7 +1172,7 @@ namespace ts { case ParsingContext.SwitchClauses: return token === SyntaxKind.CaseKeyword || token === SyntaxKind.DefaultKeyword; case ParsingContext.TypeMembers: - return isStartOfTypeMember(); + return lookAhead(isTypeMemberStart); case ParsingContext.ClassMembers: // We allow semicolons as class elements (as specified by ES6) as long as we're // not in error recovery. If we're in error recovery, we don't want an errant @@ -2214,13 +2214,13 @@ namespace ts { return finishNode(node); } - function parsePropertyOrMethodSignature(): PropertySignature | MethodSignature { - const fullStart = scanner.getStartPos(); + function parsePropertyOrMethodSignature(fullStart: number, modifiers: ModifiersArray): PropertySignature | MethodSignature { const name = parsePropertyName(); const questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { const method = createNode(SyntaxKind.MethodSignature, fullStart); + setModifiers(method, modifiers); method.name = name; method.questionToken = questionToken; @@ -2232,6 +2232,7 @@ namespace ts { } else { const property = createNode(SyntaxKind.PropertySignature, fullStart); + setModifiers(property, modifiers); property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); @@ -2248,86 +2249,51 @@ namespace ts { } } - function isStartOfTypeMember(): boolean { - switch (token) { - case SyntaxKind.OpenParenToken: - case SyntaxKind.LessThanToken: - case SyntaxKind.OpenBracketToken: // Both for indexers and computed properties - return true; - default: - if (isModifierKind(token)) { - const result = lookAhead(isStartOfIndexSignatureDeclaration); - if (result) { - return result; - } - } - - return isLiteralPropertyName() && lookAhead(isTypeMemberWithLiteralPropertyName); + function isTypeMemberStart(): boolean { + let idToken: SyntaxKind; + // Return true if we have the start of a signature member + if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + return true; } - } - - function isStartOfIndexSignatureDeclaration() { + // Eat up all modifiers, but hold on to the last one in case it is actually an identifier while (isModifierKind(token)) { + idToken = token; nextToken(); } - - return isIndexSignature(); - } - - function isTypeMemberWithLiteralPropertyName() { - nextToken(); - return token === SyntaxKind.OpenParenToken || - token === SyntaxKind.LessThanToken || - token === SyntaxKind.QuestionToken || - token === SyntaxKind.ColonToken || - canParseSemicolon(); + // Index signatures and computed property names are type members + if (token === SyntaxKind.OpenBracketToken) { + return true; + } + // Try to get the first property-like token following all modifiers + if (isLiteralPropertyName()) { + idToken = token; + nextToken(); + } + // If we were able to get any potential identifier, check that it is + // the start of a member declaration + if (idToken) { + return token === SyntaxKind.OpenParenToken || + token === SyntaxKind.LessThanToken || + token === SyntaxKind.QuestionToken || + token === SyntaxKind.ColonToken || + canParseSemicolon(); + } + return false; } function parseTypeMember(): TypeElement { - switch (token) { - case SyntaxKind.OpenParenToken: - case SyntaxKind.LessThanToken: - return parseSignatureMember(SyntaxKind.CallSignature); - case SyntaxKind.OpenBracketToken: - // Indexer or computed property - return isIndexSignature() - ? parseIndexSignatureDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined) - : parsePropertyOrMethodSignature(); - case SyntaxKind.NewKeyword: - if (lookAhead(isStartOfConstructSignature)) { - return parseSignatureMember(SyntaxKind.ConstructSignature); - } - // fall through. - case SyntaxKind.StringLiteral: - case SyntaxKind.NumericLiteral: - return parsePropertyOrMethodSignature(); - default: - // Index declaration as allowed as a type member. But as per the grammar, - // they also allow modifiers. So we have to check for an index declaration - // that might be following modifiers. This ensures that things work properly - // when incrementally parsing as the parser will produce the Index declaration - // if it has the same text regardless of whether it is inside a class or an - // object type. - if (isModifierKind(token)) { - const result = tryParse(parseIndexSignatureWithModifiers); - if (result) { - return result; - } - } - - if (tokenIsIdentifierOrKeyword(token)) { - return parsePropertyOrMethodSignature(); - } + if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + return parseSignatureMember(SyntaxKind.CallSignature); } - } - - function parseIndexSignatureWithModifiers() { - const fullStart = scanner.getStartPos(); - const decorators = parseDecorators(); + if (token === SyntaxKind.NewKeyword && lookAhead(isStartOfConstructSignature)) { + return parseSignatureMember(SyntaxKind.ConstructSignature); + } + const fullStart = getNodePos(); const modifiers = parseModifiers(); - return isIndexSignature() - ? parseIndexSignatureDeclaration(fullStart, decorators, modifiers) - : undefined; + if (isIndexSignature()) { + return parseIndexSignatureDeclaration(fullStart, /*decorators*/ undefined, modifiers); + } + return parsePropertyOrMethodSignature(fullStart, modifiers); } function isStartOfConstructSignature() { @@ -4404,6 +4370,7 @@ namespace ts { case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.PublicKeyword: + case SyntaxKind.ReadonlyKeyword: nextToken(); // ASI takes effect for this modifier. if (scanner.hasPrecedingLineBreak()) { @@ -4486,6 +4453,7 @@ namespace ts { case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.StaticKeyword: + case SyntaxKind.ReadonlyKeyword: // When these don't start a declaration, they may be the start of a class member if an identifier // immediately follows. Otherwise they're an identifier in an expression statement. return isStartOfDeclaration() || !lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine); @@ -4567,6 +4535,7 @@ namespace ts { case SyntaxKind.PublicKeyword: case SyntaxKind.AbstractKeyword: case SyntaxKind.StaticKeyword: + case SyntaxKind.ReadonlyKeyword: case SyntaxKind.GlobalKeyword: if (isStartOfDeclaration()) { return parseDeclaration(); @@ -4855,6 +4824,7 @@ namespace ts { case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.StaticKeyword: + case SyntaxKind.ReadonlyKeyword: return true; default: return false; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 398ce27ef48a3..98c46f40af107 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -857,6 +857,7 @@ namespace ts { case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: + case SyntaxKind.ReadonlyKeyword: case SyntaxKind.DeclareKeyword: diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_a_ts_file, tokenToString(modifier.kind))); return true; diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index e716da202505f..4470d7f623c73 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -98,6 +98,7 @@ namespace ts { "private": SyntaxKind.PrivateKeyword, "protected": SyntaxKind.ProtectedKeyword, "public": SyntaxKind.PublicKeyword, + "readonly": SyntaxKind.ReadonlyKeyword, "require": SyntaxKind.RequireKeyword, "global": SyntaxKind.GlobalKeyword, "return": SyntaxKind.ReturnKeyword, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ca94060d86900..6fd935f7ae3d4 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -163,6 +163,7 @@ namespace ts { IsKeyword, ModuleKeyword, NamespaceKeyword, + ReadonlyKeyword, RequireKeyword, NumberKeyword, SetKeyword, @@ -369,32 +370,33 @@ namespace ts { } export const enum NodeFlags { - None = 0, - Export = 1 << 1, // Declarations - Ambient = 1 << 2, // Declarations - Public = 1 << 3, // Property/Method - Private = 1 << 4, // Property/Method - Protected = 1 << 5, // Property/Method - Static = 1 << 6, // Property/Method - Abstract = 1 << 7, // Class/Method/ConstructSignature - Async = 1 << 8, // Property/Method/Function - Default = 1 << 9, // Function/Class (export default declaration) - MultiLine = 1 << 10, // Multi-line array or object literal - Synthetic = 1 << 11, // Synthetic node (for full fidelity) - DeclarationFile = 1 << 12, // Node is a .d.ts file - Let = 1 << 13, // Variable declaration - Const = 1 << 14, // Variable declaration - OctalLiteral = 1 << 15, // Octal numeric literal - Namespace = 1 << 16, // Namespace declaration - ExportContext = 1 << 17, // Export context (initialized by binding) - ContainsThis = 1 << 18, // Interface contains references to "this" - HasImplicitReturn = 1 << 19, // If function implicitly returns on one of codepaths (initialized by binding) - HasExplicitReturn = 1 << 20, // If function has explicit reachable return on one of codepaths (initialized by binding) - GlobalAugmentation = 1 << 21, // Set if module declaration is an augmentation for the global scope - HasClassExtends = 1 << 22, // If the file has a non-ambient class with an extends clause in ES5 or lower (initialized by binding) - HasDecorators = 1 << 23, // If the file has decorators (initialized by binding) - HasParamDecorators = 1 << 24, // If the file has parameter decorators (initialized by binding) - HasAsyncFunctions = 1 << 25, // If the file has async functions (initialized by binding) + None = 0, + Export = 1 << 0, // Declarations + Ambient = 1 << 1, // Declarations + Public = 1 << 2, // Property/Method + Private = 1 << 3, // Property/Method + Protected = 1 << 4, // Property/Method + Static = 1 << 5, // Property/Method + Readonly = 1 << 6, // Property/Method + Abstract = 1 << 7, // Class/Method/ConstructSignature + Async = 1 << 8, // Property/Method/Function + Default = 1 << 9, // Function/Class (export default declaration) + MultiLine = 1 << 10, // Multi-line array or object literal + Synthetic = 1 << 11, // Synthetic node (for full fidelity) + DeclarationFile = 1 << 12, // Node is a .d.ts file + Let = 1 << 13, // Variable declaration + Const = 1 << 14, // Variable declaration + OctalLiteral = 1 << 15, // Octal numeric literal + Namespace = 1 << 16, // Namespace declaration + ExportContext = 1 << 17, // Export context (initialized by binding) + ContainsThis = 1 << 18, // Interface contains references to "this" + HasImplicitReturn = 1 << 19, // If function implicitly returns on one of codepaths (initialized by binding) + HasExplicitReturn = 1 << 20, // If function has explicit reachable return on one of codepaths (initialized by binding) + GlobalAugmentation = 1 << 21, // Set if module declaration is an augmentation for the global scope + HasClassExtends = 1 << 22, // If the file has a non-ambient class with an extends clause in ES5 or lower (initialized by binding) + HasDecorators = 1 << 23, // If the file has decorators (initialized by binding) + HasParamDecorators = 1 << 24, // If the file has parameter decorators (initialized by binding) + HasAsyncFunctions = 1 << 25, // If the file has async functions (initialized by binding) Modifier = Export | Ambient | Public | Private | Protected | Static | Abstract | Default | Async, AccessibilityModifier = Public | Private | Protected, @@ -2074,6 +2076,7 @@ namespace ts { resolvedAwaitedType?: Type; // Cached awaited type of type node resolvedSignature?: Signature; // Cached signature of signature node or call expression resolvedSymbol?: Symbol; // Cached name resolution result + resolvedIndexInfo?: IndexInfo; // Cached indexing info resolution result flags?: NodeCheckFlags; // Set of flags specific to Node enumMemberValue?: number; // Constant value of enum member isVisible?: boolean; // Is this node visible @@ -2181,8 +2184,8 @@ namespace ts { declaredProperties: Symbol[]; // Declared members declaredCallSignatures: Signature[]; // Declared call signatures declaredConstructSignatures: Signature[]; // Declared construct signatures - declaredStringIndexType: Type; // Declared string index type - declaredNumberIndexType: Type; // Declared numeric index type + declaredStringIndexInfo: IndexInfo; // Declared string indexing info + declaredNumberIndexInfo: IndexInfo; // Declared numeric indexing info } // Type references (TypeFlags.Reference). When a class or interface has type parameters or @@ -2234,8 +2237,8 @@ namespace ts { properties: Symbol[]; // Properties callSignatures: Signature[]; // Call signatures of type constructSignatures: Signature[]; // Construct signatures of type - stringIndexType?: Type; // String index type - numberIndexType?: Type; // Numeric index type + stringIndexInfo?: IndexInfo; // String indexing info + numberIndexInfo?: IndexInfo; // Numeric indexing info } /* @internal */ @@ -2298,6 +2301,12 @@ namespace ts { Number, } + export interface IndexInfo { + type: Type; + isReadonly: boolean; + declaration?: SignatureDeclaration; + } + /* @internal */ export interface TypeMapper { (t: TypeParameter): Type; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4622f92b5df21..9b1ad62cbf200 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1582,6 +1582,7 @@ namespace ts { case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: + case SyntaxKind.ReadonlyKeyword: case SyntaxKind.StaticKeyword: return true; } @@ -2313,6 +2314,7 @@ namespace ts { case SyntaxKind.ConstKeyword: return NodeFlags.Const; case SyntaxKind.DefaultKeyword: return NodeFlags.Default; case SyntaxKind.AsyncKeyword: return NodeFlags.Async; + case SyntaxKind.ReadonlyKeyword: return NodeFlags.Readonly; } return 0; } diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index dbd4d37ef966d..31cf0ca31369d 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -2,8 +2,8 @@ /// ECMAScript APIs ///////////////////////////// -declare var NaN: number; -declare var Infinity: number; +declare const NaN: number; +declare const Infinity: number; /** * Evaluates JavaScript code and executes it. @@ -113,7 +113,7 @@ interface ObjectConstructor { (value: any): any; /** A reference to the prototype for a class of objects. */ - prototype: Object; + readonly prototype: Object; /** * Returns the prototype of an object. @@ -204,7 +204,7 @@ interface ObjectConstructor { /** * Provides functionality common to all JavaScript objects. */ -declare var Object: ObjectConstructor; +declare const Object: ObjectConstructor; /** * Creates a new function. @@ -233,7 +233,7 @@ interface Function { bind(thisArg: any, ...argArray: any[]): any; prototype: any; - length: number; + readonly length: number; // Non-standard extensions arguments: any; @@ -247,10 +247,10 @@ interface FunctionConstructor { */ new (...args: string[]): Function; (...args: string[]): Function; - prototype: Function; + readonly prototype: Function; } -declare var Function: FunctionConstructor; +declare const Function: FunctionConstructor; interface IArguments { [index: number]: any; @@ -398,7 +398,7 @@ interface String { trim(): string; /** Returns the length of a String object. */ - length: number; + readonly length: number; // IE extensions /** @@ -411,20 +411,20 @@ interface String { /** Returns the primitive value of the specified object. */ valueOf(): string; - [index: number]: string; + readonly [index: number]: string; } interface StringConstructor { new (value?: any): String; (value?: any): string; - prototype: String; + readonly prototype: String; fromCharCode(...codes: number[]): string; } /** * Allows manipulation and formatting of text strings and determination and location of substrings within strings. */ -declare var String: StringConstructor; +declare const String: StringConstructor; interface Boolean { /** Returns the primitive value of the specified object. */ @@ -434,10 +434,10 @@ interface Boolean { interface BooleanConstructor { new (value?: any): Boolean; (value?: any): boolean; - prototype: Boolean; + readonly prototype: Boolean; } -declare var Boolean: BooleanConstructor; +declare const Boolean: BooleanConstructor; interface Number { /** @@ -471,57 +471,57 @@ interface Number { interface NumberConstructor { new (value?: any): Number; (value?: any): number; - prototype: Number; + readonly prototype: Number; /** The largest number that can be represented in JavaScript. Equal to approximately 1.79E+308. */ - MAX_VALUE: number; + readonly MAX_VALUE: number; /** The closest number to zero that can be represented in JavaScript. Equal to approximately 5.00E-324. */ - MIN_VALUE: number; + readonly MIN_VALUE: number; /** * A value that is not a number. * In equality comparisons, NaN does not equal any value, including itself. To test whether a value is equivalent to NaN, use the isNaN function. */ - NaN: number; + readonly NaN: number; /** * A value that is less than the largest negative number that can be represented in JavaScript. * JavaScript displays NEGATIVE_INFINITY values as -infinity. */ - NEGATIVE_INFINITY: number; + readonly NEGATIVE_INFINITY: number; /** * A value greater than the largest number that can be represented in JavaScript. * JavaScript displays POSITIVE_INFINITY values as infinity. */ - POSITIVE_INFINITY: number; + readonly POSITIVE_INFINITY: number; } /** An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers. */ -declare var Number: NumberConstructor; +declare const Number: NumberConstructor; interface TemplateStringsArray extends Array { - raw: string[]; + readonly raw: string[]; } interface Math { /** The mathematical constant e. This is Euler's number, the base of natural logarithms. */ - E: number; + readonly E: number; /** The natural logarithm of 10. */ - LN10: number; + readonly LN10: number; /** The natural logarithm of 2. */ - LN2: number; + readonly LN2: number; /** The base-2 logarithm of e. */ - LOG2E: number; + readonly LOG2E: number; /** The base-10 logarithm of e. */ - LOG10E: number; + readonly LOG10E: number; /** Pi. This is the ratio of the circumference of a circle to its diameter. */ - PI: number; + readonly PI: number; /** The square root of 0.5, or, equivalently, one divided by the square root of 2. */ - SQRT1_2: number; + readonly SQRT1_2: number; /** The square root of 2. */ - SQRT2: number; + readonly SQRT2: number; /** * Returns the absolute value of a number (the value without regard to whether it is positive or negative). * For example, the absolute value of -5 is the same as the absolute value of 5. @@ -614,7 +614,7 @@ interface Math { tan(x: number): number; } /** An intrinsic object that provides basic mathematics functionality and constants. */ -declare var Math: Math; +declare const Math: Math; /** Enables basic storage and retrieval of dates and times. */ interface Date { @@ -776,7 +776,7 @@ interface DateConstructor { new (value: string): Date; new (year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date; (): string; - prototype: Date; + readonly prototype: Date; /** * Parses a string containing a date, and returns the number of milliseconds between that date and midnight, January 1, 1970. * @param s A date string @@ -796,7 +796,7 @@ interface DateConstructor { now(): number; } -declare var Date: DateConstructor; +declare const Date: DateConstructor; interface RegExpMatchArray extends Array { index?: number; @@ -822,16 +822,16 @@ interface RegExp { test(string: string): boolean; /** Returns a copy of the text of the regular expression pattern. Read-only. The regExp argument is a Regular expression object. It can be a variable name or a literal. */ - source: string; + readonly source: string; /** Returns a Boolean value indicating the state of the global flag (g) used with a regular expression. Default is false. Read-only. */ - global: boolean; + readonly global: boolean; /** Returns a Boolean value indicating the state of the ignoreCase flag (i) used with a regular expression. Default is false. Read-only. */ - ignoreCase: boolean; + readonly ignoreCase: boolean; /** Returns a Boolean value indicating the state of the multiline flag (m) used with a regular expression. Default is false. Read-only. */ - multiline: boolean; + readonly multiline: boolean; lastIndex: number; @@ -842,7 +842,7 @@ interface RegExp { interface RegExpConstructor { new (pattern: string, flags?: string): RegExp; (pattern: string, flags?: string): RegExp; - prototype: RegExp; + readonly prototype: RegExp; // Non-standard extensions $1: string; @@ -857,7 +857,7 @@ interface RegExpConstructor { lastMatch: string; } -declare var RegExp: RegExpConstructor; +declare const RegExp: RegExpConstructor; interface Error { name: string; @@ -867,10 +867,10 @@ interface Error { interface ErrorConstructor { new (message?: string): Error; (message?: string): Error; - prototype: Error; + readonly prototype: Error; } -declare var Error: ErrorConstructor; +declare const Error: ErrorConstructor; interface EvalError extends Error { } @@ -878,10 +878,10 @@ interface EvalError extends Error { interface EvalErrorConstructor { new (message?: string): EvalError; (message?: string): EvalError; - prototype: EvalError; + readonly prototype: EvalError; } -declare var EvalError: EvalErrorConstructor; +declare const EvalError: EvalErrorConstructor; interface RangeError extends Error { } @@ -889,10 +889,10 @@ interface RangeError extends Error { interface RangeErrorConstructor { new (message?: string): RangeError; (message?: string): RangeError; - prototype: RangeError; + readonly prototype: RangeError; } -declare var RangeError: RangeErrorConstructor; +declare const RangeError: RangeErrorConstructor; interface ReferenceError extends Error { } @@ -900,10 +900,10 @@ interface ReferenceError extends Error { interface ReferenceErrorConstructor { new (message?: string): ReferenceError; (message?: string): ReferenceError; - prototype: ReferenceError; + readonly prototype: ReferenceError; } -declare var ReferenceError: ReferenceErrorConstructor; +declare const ReferenceError: ReferenceErrorConstructor; interface SyntaxError extends Error { } @@ -911,10 +911,10 @@ interface SyntaxError extends Error { interface SyntaxErrorConstructor { new (message?: string): SyntaxError; (message?: string): SyntaxError; - prototype: SyntaxError; + readonly prototype: SyntaxError; } -declare var SyntaxError: SyntaxErrorConstructor; +declare const SyntaxError: SyntaxErrorConstructor; interface TypeError extends Error { } @@ -922,10 +922,10 @@ interface TypeError extends Error { interface TypeErrorConstructor { new (message?: string): TypeError; (message?: string): TypeError; - prototype: TypeError; + readonly prototype: TypeError; } -declare var TypeError: TypeErrorConstructor; +declare const TypeError: TypeErrorConstructor; interface URIError extends Error { } @@ -933,10 +933,10 @@ interface URIError extends Error { interface URIErrorConstructor { new (message?: string): URIError; (message?: string): URIError; - prototype: URIError; + readonly prototype: URIError; } -declare var URIError: URIErrorConstructor; +declare const URIError: URIErrorConstructor; interface JSON { /** @@ -981,13 +981,115 @@ interface JSON { /** * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. */ -declare var JSON: JSON; +declare const JSON: JSON; ///////////////////////////// /// ECMAScript Array API (specially handled by compiler) ///////////////////////////// +interface ReadonlyArray { + /** + * Gets the length of the array. This is a number one higher than the highest element defined in an array. + */ + readonly length: number; + /** + * Returns a string representation of an array. + */ + toString(): string; + toLocaleString(): string; + /** + * Combines two or more arrays. + * @param items Additional items to add to the end of array1. + */ + concat>(...items: U[]): T[]; + /** + * Combines two or more arrays. + * @param items Additional items to add to the end of array1. + */ + concat(...items: T[]): T[]; + /** + * Adds all the elements of an array separated by the specified separator string. + * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma. + */ + join(separator?: string): string; + /** + * Returns a section of an array. + * @param start The beginning of the specified portion of the array. + * @param end The end of the specified portion of the array. + */ + slice(start?: number, end?: number): T[]; + /** + * Returns the index of the first occurrence of a value in an array. + * @param searchElement The value to locate in the array. + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0. + */ + indexOf(searchElement: T, fromIndex?: number): number; + + /** + * Returns the index of the last occurrence of a specified value in an array. + * @param searchElement The value to locate in the array. + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array. + */ + lastIndexOf(searchElement: T, fromIndex?: number): number; + /** + * Determines whether all the members of an array satisfy the specified test. + * @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + every(callbackfn: (value: T, index: number, array: ReadonlyArray) => boolean, thisArg?: any): boolean; + /** + * Determines whether the specified callback function returns true for any element of an array. + * @param callbackfn A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + some(callbackfn: (value: T, index: number, array: ReadonlyArray) => boolean, thisArg?: any): boolean; + /** + * Performs the specified action for each element in an array. + * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + forEach(callbackfn: (value: T, index: number, array: ReadonlyArray) => void, thisArg?: any): void; + /** + * Calls a defined callback function on each element of an array, and returns an array that contains the results. + * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + map(callbackfn: (value: T, index: number, array: ReadonlyArray) => U, thisArg?: any): U[]; + /** + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + filter(callbackfn: (value: T, index: number, array: ReadonlyArray) => boolean, thisArg?: any): T[]; + /** + * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray) => T, initialValue?: T): T; + /** + * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: ReadonlyArray) => U, initialValue: U): U; + /** + * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray) => T, initialValue?: T): T; + /** + * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: ReadonlyArray) => U, initialValue: U): U; + + readonly [n: number]: T; +} + interface Array { /** * Gets or sets the length of the array. This is a number one higher than the highest element defined in an array. @@ -1036,19 +1138,16 @@ interface Array { * @param end The end of the specified portion of the array. */ slice(start?: number, end?: number): T[]; - /** * Sorts an array. * @param compareFn The name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order. */ sort(compareFn?: (a: T, b: T) => number): T[]; - /** * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. * @param start The zero-based location in the array from which to start removing elements. */ splice(start: number): T[]; - /** * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. * @param start The zero-based location in the array from which to start removing elements. @@ -1056,62 +1155,53 @@ interface Array { * @param items Elements to insert into the array in place of the deleted elements. */ splice(start: number, deleteCount: number, ...items: T[]): T[]; - /** * Inserts new elements at the start of an array. * @param items Elements to insert at the start of the Array. */ unshift(...items: T[]): number; - /** * Returns the index of the first occurrence of a value in an array. * @param searchElement The value to locate in the array. * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0. */ indexOf(searchElement: T, fromIndex?: number): number; - /** * Returns the index of the last occurrence of a specified value in an array. * @param searchElement The value to locate in the array. * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array. */ lastIndexOf(searchElement: T, fromIndex?: number): number; - /** * Determines whether all the members of an array satisfy the specified test. * @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ every(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; - /** * Determines whether the specified callback function returns true for any element of an array. * @param callbackfn A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; - /** * Performs the specified action for each element in an array. * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; - /** * Calls a defined callback function on each element of an array, and returns an array that contains the results. * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; - /** * Returns the elements of an array that meet the condition specified in a callback function. * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ filter(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): T[]; - /** * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. @@ -1124,7 +1214,6 @@ interface Array { * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. */ reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; - /** * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. @@ -1149,10 +1238,10 @@ interface ArrayConstructor { (arrayLength: number): T[]; (...items: T[]): T[]; isArray(arg: any): arg is Array; - prototype: Array; + readonly prototype: Array; } -declare var Array: ArrayConstructor; +declare const Array: ArrayConstructor; interface TypedPropertyDescriptor { enumerable?: boolean; @@ -1182,11 +1271,10 @@ interface PromiseLike { } interface ArrayLike { - length: number; - [n: number]: T; + readonly length: number; + readonly [n: number]: T; } - /** * Represents a raw buffer of binary data, which is used to store data for the * different typed arrays. ArrayBuffers cannot be read from or written to directly, @@ -1197,7 +1285,7 @@ interface ArrayBuffer { /** * Read-only. The length of the ArrayBuffer (in bytes). */ - byteLength: number; + readonly byteLength: number; /** * Returns a section of an ArrayBuffer. @@ -1206,11 +1294,11 @@ interface ArrayBuffer { } interface ArrayBufferConstructor { - prototype: ArrayBuffer; + readonly prototype: ArrayBuffer; new (byteLength: number): ArrayBuffer; isView(arg: any): arg is ArrayBufferView; } -declare var ArrayBuffer: ArrayBufferConstructor; +declare const ArrayBuffer: ArrayBufferConstructor; interface ArrayBufferView { /** @@ -1230,9 +1318,9 @@ interface ArrayBufferView { } interface DataView { - buffer: ArrayBuffer; - byteLength: number; - byteOffset: number; + readonly buffer: ArrayBuffer; + readonly byteLength: number; + readonly byteOffset: number; /** * Gets the Float32 value at the specified byte offset from the start of the view. There is * no alignment constraint; multi-byte values may be fetched from any offset. @@ -1360,7 +1448,7 @@ interface DataView { interface DataViewConstructor { new (buffer: ArrayBuffer, byteOffset?: number, byteLength?: number): DataView; } -declare var DataView: DataViewConstructor; +declare const DataView: DataViewConstructor; /** * A typed array of 8-bit integer values. The contents are initialized to 0. If the requested @@ -1370,22 +1458,22 @@ interface Int8Array { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -1484,7 +1572,7 @@ interface Int8Array { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -1608,7 +1696,7 @@ interface Int8Array { [index: number]: number; } interface Int8ArrayConstructor { - prototype: Int8Array; + readonly prototype: Int8Array; new (length: number): Int8Array; new (array: ArrayLike): Int8Array; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Int8Array; @@ -1616,7 +1704,7 @@ interface Int8ArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -1633,7 +1721,7 @@ interface Int8ArrayConstructor { from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Int8Array; } -declare var Int8Array: Int8ArrayConstructor; +declare const Int8Array: Int8ArrayConstructor; /** * A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the @@ -1643,22 +1731,22 @@ interface Uint8Array { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -1757,7 +1845,7 @@ interface Uint8Array { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -1882,7 +1970,7 @@ interface Uint8Array { } interface Uint8ArrayConstructor { - prototype: Uint8Array; + readonly prototype: Uint8Array; new (length: number): Uint8Array; new (array: ArrayLike): Uint8Array; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint8Array; @@ -1890,7 +1978,7 @@ interface Uint8ArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -1907,7 +1995,7 @@ interface Uint8ArrayConstructor { from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8Array; } -declare var Uint8Array: Uint8ArrayConstructor; +declare const Uint8Array: Uint8ArrayConstructor; /** * A typed array of 8-bit unsigned integer (clamped) values. The contents are initialized to 0. @@ -1917,22 +2005,22 @@ interface Uint8ClampedArray { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -2031,7 +2119,7 @@ interface Uint8ClampedArray { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -2156,7 +2244,7 @@ interface Uint8ClampedArray { } interface Uint8ClampedArrayConstructor { - prototype: Uint8ClampedArray; + readonly prototype: Uint8ClampedArray; new (length: number): Uint8ClampedArray; new (array: ArrayLike): Uint8ClampedArray; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint8ClampedArray; @@ -2164,7 +2252,7 @@ interface Uint8ClampedArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -2180,7 +2268,7 @@ interface Uint8ClampedArrayConstructor { */ from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8ClampedArray; } -declare var Uint8ClampedArray: Uint8ClampedArrayConstructor; +declare const Uint8ClampedArray: Uint8ClampedArrayConstructor; /** * A typed array of 16-bit signed integer values. The contents are initialized to 0. If the @@ -2190,22 +2278,22 @@ interface Int16Array { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -2304,7 +2392,7 @@ interface Int16Array { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -2429,7 +2517,7 @@ interface Int16Array { } interface Int16ArrayConstructor { - prototype: Int16Array; + readonly prototype: Int16Array; new (length: number): Int16Array; new (array: ArrayLike): Int16Array; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Int16Array; @@ -2437,7 +2525,7 @@ interface Int16ArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -2454,7 +2542,7 @@ interface Int16ArrayConstructor { from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Int16Array; } -declare var Int16Array: Int16ArrayConstructor; +declare const Int16Array: Int16ArrayConstructor; /** * A typed array of 16-bit unsigned integer values. The contents are initialized to 0. If the @@ -2464,22 +2552,22 @@ interface Uint16Array { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -2578,7 +2666,7 @@ interface Uint16Array { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -2703,7 +2791,7 @@ interface Uint16Array { } interface Uint16ArrayConstructor { - prototype: Uint16Array; + readonly prototype: Uint16Array; new (length: number): Uint16Array; new (array: ArrayLike): Uint16Array; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint16Array; @@ -2711,7 +2799,7 @@ interface Uint16ArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -2728,7 +2816,7 @@ interface Uint16ArrayConstructor { from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint16Array; } -declare var Uint16Array: Uint16ArrayConstructor; +declare const Uint16Array: Uint16ArrayConstructor; /** * A typed array of 32-bit signed integer values. The contents are initialized to 0. If the * requested number of bytes could not be allocated an exception is raised. @@ -2737,22 +2825,22 @@ interface Int32Array { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -2851,7 +2939,7 @@ interface Int32Array { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -2976,7 +3064,7 @@ interface Int32Array { } interface Int32ArrayConstructor { - prototype: Int32Array; + readonly prototype: Int32Array; new (length: number): Int32Array; new (array: ArrayLike): Int32Array; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Int32Array; @@ -2984,7 +3072,7 @@ interface Int32ArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -3000,7 +3088,7 @@ interface Int32ArrayConstructor { */ from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Int32Array; } -declare var Int32Array: Int32ArrayConstructor; +declare const Int32Array: Int32ArrayConstructor; /** * A typed array of 32-bit unsigned integer values. The contents are initialized to 0. If the @@ -3010,22 +3098,22 @@ interface Uint32Array { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -3124,7 +3212,7 @@ interface Uint32Array { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -3249,7 +3337,7 @@ interface Uint32Array { } interface Uint32ArrayConstructor { - prototype: Uint32Array; + readonly prototype: Uint32Array; new (length: number): Uint32Array; new (array: ArrayLike): Uint32Array; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint32Array; @@ -3257,7 +3345,7 @@ interface Uint32ArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -3273,7 +3361,7 @@ interface Uint32ArrayConstructor { */ from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint32Array; } -declare var Uint32Array: Uint32ArrayConstructor; +declare const Uint32Array: Uint32ArrayConstructor; /** * A typed array of 32-bit float values. The contents are initialized to 0. If the requested number @@ -3283,22 +3371,22 @@ interface Float32Array { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -3397,7 +3485,7 @@ interface Float32Array { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -3522,7 +3610,7 @@ interface Float32Array { } interface Float32ArrayConstructor { - prototype: Float32Array; + readonly prototype: Float32Array; new (length: number): Float32Array; new (array: ArrayLike): Float32Array; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Float32Array; @@ -3530,7 +3618,7 @@ interface Float32ArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -3547,7 +3635,7 @@ interface Float32ArrayConstructor { from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Float32Array; } -declare var Float32Array: Float32ArrayConstructor; +declare const Float32Array: Float32ArrayConstructor; /** * A typed array of 64-bit float values. The contents are initialized to 0. If the requested @@ -3557,22 +3645,22 @@ interface Float64Array { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -3671,7 +3759,7 @@ interface Float64Array { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -3796,7 +3884,7 @@ interface Float64Array { } interface Float64ArrayConstructor { - prototype: Float64Array; + readonly prototype: Float64Array; new (length: number): Float64Array; new (array: ArrayLike): Float64Array; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Float64Array; @@ -3804,7 +3892,7 @@ interface Float64ArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -3820,4 +3908,4 @@ interface Float64ArrayConstructor { */ from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Float64Array; } -declare var Float64Array: Float64ArrayConstructor; +declare const Float64Array: Float64ArrayConstructor; diff --git a/src/lib/es6.d.ts b/src/lib/es6.d.ts index f5d6b06bc470a..5d71fba2b0b3b 100644 --- a/src/lib/es6.d.ts +++ b/src/lib/es6.d.ts @@ -7,14 +7,14 @@ interface Symbol { /** Returns the primitive value of the specified object. */ valueOf(): Object; - [Symbol.toStringTag]: "Symbol"; + readonly [Symbol.toStringTag]: "Symbol"; } interface SymbolConstructor { /** * A reference to the prototype. */ - prototype: Symbol; + readonly prototype: Symbol; /** * Returns a new unique Symbol value. @@ -42,67 +42,67 @@ interface SymbolConstructor { * A method that determines if a constructor object recognizes an object as one of the * constructor’s instances. Called by the semantics of the instanceof operator. */ - hasInstance: symbol; + readonly hasInstance: symbol; /** * A Boolean value that if true indicates that an object should flatten to its array elements * by Array.prototype.concat. */ - isConcatSpreadable: symbol; + readonly isConcatSpreadable: symbol; /** * A method that returns the default iterator for an object. Called by the semantics of the * for-of statement. */ - iterator: symbol; + readonly iterator: symbol; /** * A regular expression method that matches the regular expression against a string. Called * by the String.prototype.match method. */ - match: symbol; + readonly match: symbol; /** * A regular expression method that replaces matched substrings of a string. Called by the * String.prototype.replace method. */ - replace: symbol; + readonly replace: symbol; /** * A regular expression method that returns the index within a string that matches the * regular expression. Called by the String.prototype.search method. */ - search: symbol; + readonly search: symbol; /** * A function valued property that is the constructor function that is used to create * derived objects. */ - species: symbol; + readonly species: symbol; /** * A regular expression method that splits a string at the indices that match the regular * expression. Called by the String.prototype.split method. */ - split: symbol; + readonly split: symbol; /** * A method that converts an object to a corresponding primitive value. * Called by the ToPrimitive abstract operation. */ - toPrimitive: symbol; + readonly toPrimitive: symbol; /** * A String value that is used in the creation of the default string description of an object. * Called by the built-in method Object.prototype.toString. */ - toStringTag: symbol; + readonly toStringTag: symbol; /** * An Object whose own property names are property names that are excluded from the 'with' * environment bindings of the associated objects. */ - unscopables: symbol; + readonly unscopables: symbol; } declare var Symbol: SymbolConstructor; @@ -200,7 +200,7 @@ interface Function { /** * Returns the name of the function. Function names are read-only and can not be changed. */ - name: string; + readonly name: string; /** * Determines whether the given value inherits from this function if this function was used @@ -218,7 +218,7 @@ interface NumberConstructor { * that is representable as a Number value, which is approximately: * 2.2204460492503130808472633361816 x 10‍−‍16. */ - EPSILON: number; + readonly EPSILON: number; /** * Returns true if passed value is finite. @@ -253,14 +253,14 @@ interface NumberConstructor { * a Number value. * The value of Number.MIN_SAFE_INTEGER is 9007199254740991 2^53 − 1. */ - MAX_SAFE_INTEGER: number; + readonly MAX_SAFE_INTEGER: number; /** * The value of the smallest integer n such that n and n − 1 are both exactly representable as * a Number value. * The value of Number.MIN_SAFE_INTEGER is −9007199254740991 (−(2^53 − 1)). */ - MIN_SAFE_INTEGER: number; + readonly MIN_SAFE_INTEGER: number; /** * Converts a string to a floating-point number. @@ -565,7 +565,7 @@ interface IterableIterator extends Iterator { } interface GeneratorFunction extends Function { - [Symbol.toStringTag]: "GeneratorFunction"; + readonly [Symbol.toStringTag]: "GeneratorFunction"; } interface GeneratorFunctionConstructor { @@ -575,7 +575,7 @@ interface GeneratorFunctionConstructor { */ new (...args: string[]): GeneratorFunction; (...args: string[]): GeneratorFunction; - prototype: GeneratorFunction; + readonly prototype: GeneratorFunction; } declare var GeneratorFunction: GeneratorFunctionConstructor; @@ -690,7 +690,7 @@ interface Math { */ cbrt(x: number): number; - [Symbol.toStringTag]: "Math"; + readonly [Symbol.toStringTag]: "Math"; } interface Date { @@ -776,19 +776,19 @@ interface RegExp { * * If no flags are set, the value is the empty string. */ - flags: string; + readonly flags: string; /** * Returns a Boolean value indicating the state of the sticky flag (y) used with a regular * expression. Default is false. Read-only. */ - sticky: boolean; + readonly sticky: boolean; /** * Returns a Boolean value indicating the state of the Unicode flag (u) used with a regular * expression. Default is false. Read-only. */ - unicode: boolean; + readonly unicode: boolean; } interface RegExpConstructor { @@ -804,33 +804,34 @@ interface Map { has(key: K): boolean; keys(): IterableIterator; set(key: K, value?: V): Map; - size: number; + readonly size: number; values(): IterableIterator; [Symbol.iterator]():IterableIterator<[K,V]>; - [Symbol.toStringTag]: "Map"; + readonly [Symbol.toStringTag]: "Map"; } interface MapConstructor { new (): Map; new (): Map; new (iterable: Iterable<[K, V]>): Map; - prototype: Map; + readonly prototype: Map; } declare var Map: MapConstructor; interface WeakMap { + clear(): void; delete(key: K): boolean; get(key: K): V; has(key: K): boolean; set(key: K, value?: V): WeakMap; - [Symbol.toStringTag]: "WeakMap"; + readonly [Symbol.toStringTag]: "WeakMap"; } interface WeakMapConstructor { new (): WeakMap; new (): WeakMap; new (iterable: Iterable<[K, V]>): WeakMap; - prototype: WeakMap; + readonly prototype: WeakMap; } declare var WeakMap: WeakMapConstructor; @@ -842,37 +843,38 @@ interface Set { forEach(callbackfn: (value: T, index: T, set: Set) => void, thisArg?: any): void; has(value: T): boolean; keys(): IterableIterator; - size: number; + readonly size: number; values(): IterableIterator; [Symbol.iterator]():IterableIterator; - [Symbol.toStringTag]: "Set"; + readonly [Symbol.toStringTag]: "Set"; } interface SetConstructor { new (): Set; new (): Set; new (iterable: Iterable): Set; - prototype: Set; + readonly prototype: Set; } declare var Set: SetConstructor; interface WeakSet { add(value: T): WeakSet; + clear(): void; delete(value: T): boolean; has(value: T): boolean; - [Symbol.toStringTag]: "WeakSet"; + readonly [Symbol.toStringTag]: "WeakSet"; } interface WeakSetConstructor { new (): WeakSet; new (): WeakSet; new (iterable: Iterable): WeakSet; - prototype: WeakSet; + readonly prototype: WeakSet; } declare var WeakSet: WeakSetConstructor; interface JSON { - [Symbol.toStringTag]: "JSON"; + readonly [Symbol.toStringTag]: "JSON"; } /** @@ -882,11 +884,11 @@ interface JSON { * buffer as needed. */ interface ArrayBuffer { - [Symbol.toStringTag]: "ArrayBuffer"; + readonly [Symbol.toStringTag]: "ArrayBuffer"; } interface DataView { - [Symbol.toStringTag]: "DataView"; + readonly [Symbol.toStringTag]: "DataView"; } /** @@ -907,7 +909,7 @@ interface Int8Array { */ values(): IterableIterator; [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "Int8Array"; + readonly [Symbol.toStringTag]: "Int8Array"; } interface Int8ArrayConstructor { @@ -940,7 +942,7 @@ interface Uint8Array { */ values(): IterableIterator; [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "UInt8Array"; + readonly [Symbol.toStringTag]: "UInt8Array"; } interface Uint8ArrayConstructor { @@ -976,7 +978,7 @@ interface Uint8ClampedArray { values(): IterableIterator; [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "Uint8ClampedArray"; + readonly [Symbol.toStringTag]: "Uint8ClampedArray"; } interface Uint8ClampedArrayConstructor { @@ -1014,7 +1016,7 @@ interface Int16Array { [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "Int16Array"; + readonly [Symbol.toStringTag]: "Int16Array"; } interface Int16ArrayConstructor { @@ -1047,7 +1049,7 @@ interface Uint16Array { */ values(): IterableIterator; [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "Uint16Array"; + readonly [Symbol.toStringTag]: "Uint16Array"; } interface Uint16ArrayConstructor { @@ -1080,7 +1082,7 @@ interface Int32Array { */ values(): IterableIterator; [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "Int32Array"; + readonly [Symbol.toStringTag]: "Int32Array"; } interface Int32ArrayConstructor { @@ -1113,7 +1115,7 @@ interface Uint32Array { */ values(): IterableIterator; [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "Uint32Array"; + readonly [Symbol.toStringTag]: "Uint32Array"; } interface Uint32ArrayConstructor { @@ -1146,7 +1148,7 @@ interface Float32Array { */ values(): IterableIterator; [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "Float32Array"; + readonly [Symbol.toStringTag]: "Float32Array"; } interface Float32ArrayConstructor { @@ -1179,7 +1181,7 @@ interface Float64Array { */ values(): IterableIterator; [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "Float64Array"; + readonly [Symbol.toStringTag]: "Float64Array"; } interface Float64ArrayConstructor { @@ -1256,14 +1258,14 @@ interface Promise { catch(onrejected?: (reason: any) => T | PromiseLike): Promise; catch(onrejected?: (reason: any) => void): Promise; - [Symbol.toStringTag]: "Promise"; + readonly [Symbol.toStringTag]: "Promise"; } interface PromiseConstructor { /** * A reference to the prototype. */ - prototype: Promise; + readonly prototype: Promise; /** * Creates a new Promise. @@ -1325,7 +1327,7 @@ interface PromiseConstructor { */ resolve(): Promise; - [Symbol.species]: Function; + readonly [Symbol.species]: Function; } declare var Promise: PromiseConstructor; diff --git a/tests/baselines/reference/accessorWithES5.types b/tests/baselines/reference/accessorWithES5.types index cb54e92b1847d..29471548918eb 100644 --- a/tests/baselines/reference/accessorWithES5.types +++ b/tests/baselines/reference/accessorWithES5.types @@ -21,8 +21,8 @@ class D { } var x = { ->x : { a: number; } ->{ get a() { return 1 }} : { a: number; } +>x : { readonly a: number; } +>{ get a() { return 1 }} : { readonly a: number; } get a() { return 1 } >a : number diff --git a/tests/baselines/reference/assignToEnum.errors.txt b/tests/baselines/reference/assignToEnum.errors.txt index 4846a96dbb7b8..d50daa3099f6a 100644 --- a/tests/baselines/reference/assignToEnum.errors.txt +++ b/tests/baselines/reference/assignToEnum.errors.txt @@ -1,7 +1,7 @@ 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 TS2364: Invalid left-hand side of assignment expression. -tests/cases/compiler/assignToEnum.ts(5,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 (4 errors) ==== @@ -14,9 +14,9 @@ tests/cases/compiler/assignToEnum.ts(5,1): error TS2364: Invalid left-hand side !!! error TS2364: Invalid left-hand side of assignment expression. A.foo = 1; // invalid LHS ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. A.foo = A.bar; // invalid LHS ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/assignments.errors.txt b/tests/baselines/reference/assignments.errors.txt index 9f89863f31f65..05bc4ce179418 100644 --- a/tests/baselines/reference/assignments.errors.txt +++ b/tests/baselines/reference/assignments.errors.txt @@ -1,7 +1,7 @@ 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 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(31,1): error TS2304: Cannot find name 'I'. @@ -32,7 +32,7 @@ tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): er !!! error TS2364: Invalid left-hand side of assignment expression. E.A = null; // OK per spec, Error per implementation (509581) ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. function fn() { } fn = null; // Should be error diff --git a/tests/baselines/reference/commentsOnObjectLiteral4.types b/tests/baselines/reference/commentsOnObjectLiteral4.types index 364df6e5ea1fd..f458d73ae3652 100644 --- a/tests/baselines/reference/commentsOnObjectLiteral4.types +++ b/tests/baselines/reference/commentsOnObjectLiteral4.types @@ -1,8 +1,8 @@ === tests/cases/compiler/commentsOnObjectLiteral4.ts === var v = { ->v : { bar: number; } ->{ /** * @type {number} */ get bar(): number { return this._bar; }} : { bar: number; } +>v : { readonly bar: number; } +>{ /** * @type {number} */ get bar(): number { return this._bar; }} : { readonly bar: number; } /** * @type {number} diff --git a/tests/baselines/reference/computedPropertyNames11_ES5.types b/tests/baselines/reference/computedPropertyNames11_ES5.types index e0787fc3ee712..ae626ec3cba28 100644 --- a/tests/baselines/reference/computedPropertyNames11_ES5.types +++ b/tests/baselines/reference/computedPropertyNames11_ES5.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { [0]: number; [""]: any; } ->{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { [0]: number; [""]: any; } +>v : { readonly [0]: number; [""]: any; } +>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { readonly [0]: number; [""]: any; } get [s]() { return 0; }, >s : string diff --git a/tests/baselines/reference/computedPropertyNames11_ES6.types b/tests/baselines/reference/computedPropertyNames11_ES6.types index 8ad31a7c2a14e..06dc26e984305 100644 --- a/tests/baselines/reference/computedPropertyNames11_ES6.types +++ b/tests/baselines/reference/computedPropertyNames11_ES6.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { [0]: number; [""]: any; } ->{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { [0]: number; [""]: any; } +>v : { readonly [0]: number; [""]: any; } +>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { readonly [0]: number; [""]: any; } get [s]() { return 0; }, >s : string diff --git a/tests/baselines/reference/constDeclarations-access.errors.txt b/tests/baselines/reference/constDeclarations-access.errors.txt index 04b942aec09ef..3c748cc4a5ff5 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. +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/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. \ No newline at end of file +!!! 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 diff --git a/tests/baselines/reference/constDeclarations-access2.errors.txt b/tests/baselines/reference/constDeclarations-access2.errors.txt index 6a360e11014e8..667f490a374a1 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. -tests/cases/compiler/constDeclarations-access2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(19,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(21,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +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 (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. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x += 2; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x -= 3; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x *= 4; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x /= 5; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x %= 6; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x <<= 7; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x >>= 8; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x >>>= 9; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x &= 10; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x |= 11; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x ^= 12; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x++; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. x--; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ++x; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. --x; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ++((x)); ~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be 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 577b087dff09a..a6cb124d28c57 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. -tests/cases/compiler/constDeclarations-access3.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +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 (18 errors) ==== @@ -28,61 +28,61 @@ 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. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x += 2; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x -= 3; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x *= 4; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x /= 5; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x %= 6; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x <<= 7; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x >>= 8; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x >>>= 9; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x &= 10; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x |= 11; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x ^= 12; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x++; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. M.x--; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ++M.x; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. --M.x; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ++((M.x)); ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. M["x"] = 0; ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be 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 9745c0d262497..3d7d4a704a81e 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. -tests/cases/compiler/constDeclarations-access4.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +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 (18 errors) ==== @@ -28,61 +28,61 @@ 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. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x += 2; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x -= 3; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x *= 4; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x /= 5; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x %= 6; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x <<= 7; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x >>= 8; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x >>>= 9; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x &= 10; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x |= 11; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x ^= 12; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x++; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. M.x--; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ++M.x; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. --M.x; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ++((M.x)); ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. M["x"] = 0; ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be 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 23200e50ee42b..45160bbc7cede 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. -tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(17,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(19,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +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 (18 errors) ==== @@ -24,61 +24,61 @@ tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-han // Errors m.x = 1; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x += 2; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x -= 3; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x *= 4; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x /= 5; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x %= 6; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x <<= 7; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x >>= 8; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x >>>= 9; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x &= 10; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x |= 11; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x ^= 12; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m m.x++; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. m.x--; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ++m.x; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. --m.x; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ++((m.x)); ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. m["x"] = 0; ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be 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 10501beb1a540..98b12b616f77c 100644 --- a/tests/baselines/reference/constDeclarations-errors.errors.txt +++ b/tests/baselines/reference/constDeclarations-errors.errors.txt @@ -4,7 +4,7 @@ tests/cases/compiler/constDeclarations-errors.ts(5,7): error TS1155: 'const' dec tests/cases/compiler/constDeclarations-errors.ts(5,11): error TS1155: 'const' declarations must be initialized 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,27): error TS2449: The operand of an increment or decrement operator cannot be a constant. +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(13,11): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(16,20): error TS1155: 'const' declarations must be initialized @@ -33,7 +33,7 @@ tests/cases/compiler/constDeclarations-errors.ts(16,20): error TS1155: 'const' d // error, assigning to a const for(const c8 = 0; c8 < 1; c8++) { } ~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. // error, can not be unintalized for(const c9; c9 < 1;) { } diff --git a/tests/baselines/reference/constEnumPropertyAccess2.errors.txt b/tests/baselines/reference/constEnumPropertyAccess2.errors.txt index 19b273faffa00..a943ee0096236 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 TS2364: Invalid left-hand side of assignment expression. +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 (4 errors) ==== @@ -31,5 +31,5 @@ tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(19,1): error TS23 function foo(x: G) { } G.B = 3; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.js b/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.js index 396ee75422e71..eb440c028d582 100644 --- a/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.js +++ b/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.js @@ -22,9 +22,9 @@ var /*2*/ x = point.x; //// [declFileObjectLiteralWithOnlyGetter.d.ts] declare function makePoint(x: number): { - x: number; + readonly x: number; }; declare var point: { - x: number; + readonly x: number; }; declare var x: number; diff --git a/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.types b/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.types index c0fb7b763fcfb..dd3cbe20983ad 100644 --- a/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.types +++ b/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.types @@ -1,11 +1,11 @@ === tests/cases/compiler/declFileObjectLiteralWithOnlyGetter.ts === function /*1*/makePoint(x: number) { ->makePoint : (x: number) => { x: number; } +>makePoint : (x: number) => { readonly x: number; } >x : number return { ->{ get x() { return x; }, } : { x: number; } +>{ get x() { return x; }, } : { readonly x: number; } get x() { return x; }, >x : number @@ -14,14 +14,14 @@ function /*1*/makePoint(x: number) { }; }; var /*4*/point = makePoint(2); ->point : { x: number; } ->makePoint(2) : { x: number; } ->makePoint : (x: number) => { x: number; } +>point : { readonly x: number; } +>makePoint(2) : { readonly x: number; } +>makePoint : (x: number) => { readonly x: number; } >2 : number var /*2*/x = point./*3*/x; >x : number >point./*3*/x : number ->point : { x: number; } +>point : { readonly x: number; } >x : number diff --git a/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt b/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt index a0c30e9dc93fa..29e06bc6a4e54 100644 --- a/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt +++ b/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt @@ -1,21 +1,27 @@ -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(7,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +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(12,7): error TS2304: Cannot find name 'A'. -==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts (3 errors) ==== +==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts (5 errors) ==== // -- operator on enum type enum ENUM1 { A, B, "" }; // expression var ResultIsNumber1 = --ENUM1["A"]; + ~~~~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. var ResultIsNumber2 = ENUM1.A--; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2449: The operand of an increment or decrement operator cannot be 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. ENUM1[A]--; ~~~~~~~~ diff --git a/tests/baselines/reference/downlevelLetConst18.types b/tests/baselines/reference/downlevelLetConst18.types index 42421aa80c065..1f7be6161247f 100644 --- a/tests/baselines/reference/downlevelLetConst18.types +++ b/tests/baselines/reference/downlevelLetConst18.types @@ -54,8 +54,8 @@ for (let x; ;) { >x : any ({ get foo() { return x } }) ->({ get foo() { return x } }) : { foo: any; } ->{ get foo() { return x } } : { foo: any; } +>({ get foo() { return x } }) : { readonly foo: any; } +>{ get foo() { return x } } : { readonly foo: any; } >foo : any >x : any } diff --git a/tests/baselines/reference/enumBasics.js b/tests/baselines/reference/enumBasics.js index 25aec5a72d84d..4ac41c0f3d1b8 100644 --- a/tests/baselines/reference/enumBasics.js +++ b/tests/baselines/reference/enumBasics.js @@ -12,10 +12,10 @@ var x: number = E1.A; // Enum object type is anonymous with properties of the enum type and numeric indexer var e = E1; var e: { - A: E1; - B: E1; - C: E1; - [n: number]: string; + readonly A: E1; + readonly B: E1; + readonly C: E1; + readonly [n: number]: string; }; var e: typeof E1; diff --git a/tests/baselines/reference/enumBasics.symbols b/tests/baselines/reference/enumBasics.symbols index 23f2a400741fe..ce81a80ca5fa3 100644 --- a/tests/baselines/reference/enumBasics.symbols +++ b/tests/baselines/reference/enumBasics.symbols @@ -28,20 +28,20 @@ var e = E1; var e: { >e : Symbol(e, Decl(enumBasics.ts, 11, 3), Decl(enumBasics.ts, 12, 3), Decl(enumBasics.ts, 18, 3)) - A: E1; + readonly A: E1; >A : Symbol(A, Decl(enumBasics.ts, 12, 8)) >E1 : Symbol(E1, Decl(enumBasics.ts, 0, 0)) - B: E1; ->B : Symbol(B, Decl(enumBasics.ts, 13, 10)) + readonly B: E1; +>B : Symbol(B, Decl(enumBasics.ts, 13, 19)) >E1 : Symbol(E1, Decl(enumBasics.ts, 0, 0)) - C: E1; ->C : Symbol(C, Decl(enumBasics.ts, 14, 10)) + readonly C: E1; +>C : Symbol(C, Decl(enumBasics.ts, 14, 19)) >E1 : Symbol(E1, Decl(enumBasics.ts, 0, 0)) - [n: number]: string; ->n : Symbol(n, Decl(enumBasics.ts, 16, 5)) + readonly [n: number]: string; +>n : Symbol(n, Decl(enumBasics.ts, 16, 14)) }; var e: typeof E1; diff --git a/tests/baselines/reference/enumBasics.types b/tests/baselines/reference/enumBasics.types index 87f6f12b6b2ef..cecd8f5113606 100644 --- a/tests/baselines/reference/enumBasics.types +++ b/tests/baselines/reference/enumBasics.types @@ -28,19 +28,19 @@ var e = E1; var e: { >e : typeof E1 - A: E1; + readonly A: E1; >A : E1 >E1 : E1 - B: E1; + readonly B: E1; >B : E1 >E1 : E1 - C: E1; + readonly C: E1; >C : E1 >E1 : E1 - [n: number]: string; + readonly [n: number]: string; >n : number }; diff --git a/tests/baselines/reference/externalModuleImmutableBindings.errors.txt b/tests/baselines/reference/externalModuleImmutableBindings.errors.txt index a6040c154f097..c8c61b2dc816b 100644 --- a/tests/baselines/reference/externalModuleImmutableBindings.errors.txt +++ b/tests/baselines/reference/externalModuleImmutableBindings.errors.txt @@ -1,11 +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(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(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(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(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"'. @@ -13,7 +25,7 @@ tests/cases/compiler/f2.ts(41,13): error TS2339: Property 'blah' does not exist ==== tests/cases/compiler/f1.ts (0 errors) ==== export var x = 1; -==== tests/cases/compiler/f2.ts (10 errors) ==== +==== tests/cases/compiler/f2.ts (22 errors) ==== // all mutations below are illegal and should be fixed import * as stuff from './f1'; @@ -21,26 +33,42 @@ 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. stuff['x'] = 1; + ~~~~~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be 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. stuff['x']++; + ~~~~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be 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. (stuff['x']) = 1; + ~~~~~~~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be 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. (stuff['x'])++; + ~~~~~~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. (stuff['blah'])++; (stuff[n])++; @@ -48,10 +76,14 @@ tests/cases/compiler/f2.ts(41,13): error TS2339: Property 'blah' does not exist ~~~~~~~ !!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. for (stuff.x of []) {} + ~~~~~~~ +!!! error TS2485: The left-hand side of a 'for...of' statement cannot be 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'. for (stuff['x'] of []) {} + ~~~~~~~~~~ +!!! error TS2485: The left-hand side of a 'for...of' statement cannot be 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"'. @@ -65,10 +97,14 @@ tests/cases/compiler/f2.ts(41,13): error TS2339: Property 'blah' does not exist ~~~~~~~~~ !!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. for ((stuff.x) of []) {} + ~~~~~~~~~ +!!! error TS2485: The left-hand side of a 'for...of' statement cannot be 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'. for ((stuff['x']) of []) {} + ~~~~~~~~~~~~ +!!! error TS2485: The left-hand side of a 'for...of' statement cannot be 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-of2.errors.txt b/tests/baselines/reference/for-of2.errors.txt index 0b5133cde13ee..f4f39f60f670b 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 previously defined constant. +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 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 previously defined constant. \ No newline at end of file +!!! 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 diff --git a/tests/baselines/reference/importsImplicitlyReadonly.errors.txt b/tests/baselines/reference/importsImplicitlyReadonly.errors.txt new file mode 100644 index 0000000000000..cc6e1918020e5 --- /dev/null +++ b/tests/baselines/reference/importsImplicitlyReadonly.errors.txt @@ -0,0 +1,34 @@ +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 (4 errors) ==== + import { x, y } from "./a"; + import * as a1 from "./a"; + import a2 = require("./a"); + const a3 = a1; + + x = 1; // Error + ~ +!!! error TS2364: Invalid left-hand side of assignment expression. + y = 1; // Error + ~ +!!! error TS2364: Invalid left-hand side of assignment expression. + a1.x = 1; // Error + ~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be 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. + a2.x = 1; + a2.y = 1; + a3.x = 1; + a3.y = 1; +==== tests/cases/conformance/externalModules/a.ts (0 errors) ==== + + export var x = 1; + var y = 1; + export { y }; + \ No newline at end of file diff --git a/tests/baselines/reference/importsImplicitlyReadonly.js b/tests/baselines/reference/importsImplicitlyReadonly.js new file mode 100644 index 0000000000000..4630de598cc46 --- /dev/null +++ b/tests/baselines/reference/importsImplicitlyReadonly.js @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/externalModules/importsImplicitlyReadonly.ts] //// + +//// [a.ts] + +export var x = 1; +var y = 1; +export { y }; + +//// [b.ts] +import { x, y } from "./a"; +import * as a1 from "./a"; +import a2 = require("./a"); +const a3 = a1; + +x = 1; // Error +y = 1; // Error +a1.x = 1; // Error +a1.y = 1; // Error +a2.x = 1; +a2.y = 1; +a3.x = 1; +a3.y = 1; + +//// [a.js] +"use strict"; +exports.x = 1; +var y = 1; +exports.y = y; +//// [b.js] +"use strict"; +var a_1 = require("./a"); +var a1 = require("./a"); +var a2 = require("./a"); +var a3 = a1; +a_1.x = 1; // Error +a_1.y = 1; // Error +a1.x = 1; // Error +a1.y = 1; // Error +a2.x = 1; +a2.y = 1; +a3.x = 1; +a3.y = 1; diff --git a/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt b/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt index 9bcf6c7612f66..fc8b682b59e86 100644 --- a/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt +++ b/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt @@ -1,21 +1,27 @@ -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(7,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(12,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +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 (2 errors) ==== +==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts (4 errors) ==== // ++ operator on enum type enum ENUM1 { A, B, "" }; // expression var ResultIsNumber1 = ++ENUM1["B"]; + ~~~~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. var ResultIsNumber2 = ENUM1.B++; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2449: The operand of an increment or decrement operator cannot be 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. ENUM1.B++; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. \ No newline at end of file +!!! 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 diff --git a/tests/baselines/reference/interfaceWithAccessibilityModifiers.errors.txt b/tests/baselines/reference/interfaceWithAccessibilityModifiers.errors.txt index ecf803d522bd6..1c6f8f1939dda 100644 --- a/tests/baselines/reference/interfaceWithAccessibilityModifiers.errors.txt +++ b/tests/baselines/reference/interfaceWithAccessibilityModifiers.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts(3,5): error TS1131: Property or signature expected. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts(4,5): error TS1131: Property or signature expected. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts(5,5): error TS1131: Property or signature expected. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts(3,5): error TS1070: 'public' modifier cannot appear on a type member. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts(4,5): error TS1070: 'private' modifier cannot appear on a type member. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts(5,5): error TS1070: 'protected' modifier cannot appear on a type member. ==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts (3 errors) ==== @@ -8,11 +8,11 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibil interface Foo { public a: any; ~~~~~~ -!!! error TS1131: Property or signature expected. +!!! error TS1070: 'public' modifier cannot appear on a type member. private b: any; ~~~~~~~ -!!! error TS1131: Property or signature expected. +!!! error TS1070: 'private' modifier cannot appear on a type member. protected c: any; ~~~~~~~~~ -!!! error TS1131: Property or signature expected. +!!! error TS1070: 'protected' modifier cannot appear on a type member. } \ No newline at end of file diff --git a/tests/baselines/reference/interfaceWithPrivateMember.errors.txt b/tests/baselines/reference/interfaceWithPrivateMember.errors.txt index dc1cfeabed5e3..ecbd9ec293c29 100644 --- a/tests/baselines/reference/interfaceWithPrivateMember.errors.txt +++ b/tests/baselines/reference/interfaceWithPrivateMember.errors.txt @@ -1,32 +1,26 @@ -tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts(5,5): error TS1131: Property or signature expected. -tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts(9,5): error TS1131: Property or signature expected. -tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts(13,5): error TS1131: Property or signature expected. -tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts(13,16): error TS2304: Cannot find name 'string'. -tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts(14,1): error TS1128: Declaration or statement expected. +tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts(5,5): error TS1070: 'private' modifier cannot appear on a type member. +tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts(9,5): error TS1070: 'private' modifier cannot appear on a type member. +tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts(13,5): error TS1070: 'private' modifier cannot appear on a type member. -==== tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts (5 errors) ==== +==== tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts (3 errors) ==== // interfaces do not permit private members, these are errors interface I { private x: string; ~~~~~~~ -!!! error TS1131: Property or signature expected. +!!! error TS1070: 'private' modifier cannot appear on a type member. } interface I2 { private y: T; ~~~~~~~ -!!! error TS1131: Property or signature expected. +!!! error TS1070: 'private' modifier cannot appear on a type member. } var x: { private y: string; ~~~~~~~ -!!! error TS1131: Property or signature expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'string'. - } - ~ -!!! error TS1128: Declaration or statement expected. \ No newline at end of file +!!! error TS1070: 'private' modifier cannot appear on a type member. + } \ No newline at end of file diff --git a/tests/baselines/reference/interfaceWithPrivateMember.js b/tests/baselines/reference/interfaceWithPrivateMember.js index ceb388b1eae26..d59037cf058cc 100644 --- a/tests/baselines/reference/interfaceWithPrivateMember.js +++ b/tests/baselines/reference/interfaceWithPrivateMember.js @@ -17,4 +17,3 @@ var x: { //// [interfaceWithPrivateMember.js] // interfaces do not permit private members, these are errors var x; -y: string; diff --git a/tests/baselines/reference/invalidUndefinedAssignments.errors.txt b/tests/baselines/reference/invalidUndefinedAssignments.errors.txt index 4c32b1a6c8ed6..5eff2e7ff1afa 100644 --- a/tests/baselines/reference/invalidUndefinedAssignments.errors.txt +++ b/tests/baselines/reference/invalidUndefinedAssignments.errors.txt @@ -1,5 +1,5 @@ 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 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(14,1): error TS2304: Cannot find name 'I'. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. @@ -15,7 +15,7 @@ tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.t !!! error TS2364: Invalid left-hand side of assignment expression. E.A = x; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. class C { foo: string } var f: C; diff --git a/tests/baselines/reference/modifiersOnInterfaceIndexSignature1.errors.txt b/tests/baselines/reference/modifiersOnInterfaceIndexSignature1.errors.txt index b325710a9f066..e09a73ff68aeb 100644 --- a/tests/baselines/reference/modifiersOnInterfaceIndexSignature1.errors.txt +++ b/tests/baselines/reference/modifiersOnInterfaceIndexSignature1.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/modifiersOnInterfaceIndexSignature1.ts(2,3): error TS1145: Modifiers not permitted on index signature members. +tests/cases/compiler/modifiersOnInterfaceIndexSignature1.ts(2,3): error TS1071: 'public' modifier cannot appear on an index signature. ==== tests/cases/compiler/modifiersOnInterfaceIndexSignature1.ts (1 errors) ==== interface I { public [a: string]: number; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'public' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralGettersAndSetters.errors.txt b/tests/baselines/reference/objectLiteralGettersAndSetters.errors.txt index 4e04b856d8c5c..1290859fbf9f0 100644 --- a/tests/baselines/reference/objectLiteralGettersAndSetters.errors.txt +++ b/tests/baselines/reference/objectLiteralGettersAndSetters.errors.txt @@ -79,13 +79,13 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralGettersAndSetter var getter1 = { get x(): string { return undefined; } }; ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - var getter1: { x: string; } + var getter1: { readonly x: string; } // Get accessor only, type of the property is the inferred return type of the get accessor var getter2 = { get x() { return ''; } }; ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - var getter2: { x: string; } + var getter2: { readonly x: string; } // Set accessor only, type of the property is the param type of the set accessor var setter1 = { set x(n: number) { } }; diff --git a/tests/baselines/reference/objectLiteralGettersAndSetters.js b/tests/baselines/reference/objectLiteralGettersAndSetters.js index d226c2c55697f..d3a9d64308601 100644 --- a/tests/baselines/reference/objectLiteralGettersAndSetters.js +++ b/tests/baselines/reference/objectLiteralGettersAndSetters.js @@ -17,11 +17,11 @@ var callSig3: { num: (n: number) => string; }; // Get accessor only, type of the property is the annotated return type of the get accessor var getter1 = { get x(): string { return undefined; } }; -var getter1: { x: string; } +var getter1: { readonly x: string; } // Get accessor only, type of the property is the inferred return type of the get accessor var getter2 = { get x() { return ''; } }; -var getter2: { x: string; } +var getter2: { readonly x: string; } // Set accessor only, type of the property is the param type of the set accessor var setter1 = { set x(n: number) { } }; diff --git a/tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt b/tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt index d448aaa3f294c..1e94ed36b231b 100644 --- a/tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt +++ b/tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,11): error TS1030: 'static' modifier already seen. +tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,4): error TS1071: 'static' modifier cannot appear on an index signature. ==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts (1 errors) ==== class C { static static [x: string]: string; - ~~~~~~ -!!! error TS1030: 'static' modifier already seen. + ~~~~~~ +!!! error TS1071: 'static' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/parserIndexMemberDeclaration6.errors.txt b/tests/baselines/reference/parserIndexMemberDeclaration6.errors.txt index 713031dbe4fe7..df15ae5950e1c 100644 --- a/tests/baselines/reference/parserIndexMemberDeclaration6.errors.txt +++ b/tests/baselines/reference/parserIndexMemberDeclaration6.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration6.ts(2,4): error TS1145: Modifiers not permitted on index signature members. +tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration6.ts(2,4): error TS1071: 'static' modifier cannot appear on an index signature. ==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration6.ts (1 errors) ==== class C { static [x: string]: string; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'static' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/parserIndexMemberDeclaration7.errors.txt b/tests/baselines/reference/parserIndexMemberDeclaration7.errors.txt index 64984ee642f2b..ebbfaf8af4d94 100644 --- a/tests/baselines/reference/parserIndexMemberDeclaration7.errors.txt +++ b/tests/baselines/reference/parserIndexMemberDeclaration7.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration7.ts(2,4): error TS1145: Modifiers not permitted on index signature members. +tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration7.ts(2,4): error TS1071: 'public' modifier cannot appear on an index signature. ==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration7.ts (1 errors) ==== class C { public [x: string]: string; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'public' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/parserIndexMemberDeclaration8.errors.txt b/tests/baselines/reference/parserIndexMemberDeclaration8.errors.txt index 1fffaa299ceab..4a5eec13cb56c 100644 --- a/tests/baselines/reference/parserIndexMemberDeclaration8.errors.txt +++ b/tests/baselines/reference/parserIndexMemberDeclaration8.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration8.ts(2,4): error TS1145: Modifiers not permitted on index signature members. +tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration8.ts(2,4): error TS1071: 'private' modifier cannot appear on an index signature. ==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration8.ts (1 errors) ==== class C { private [x: string]: string; ~~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'private' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/parserIndexMemberDeclaration9.errors.txt b/tests/baselines/reference/parserIndexMemberDeclaration9.errors.txt index 493a7894499f2..88360adcd701a 100644 --- a/tests/baselines/reference/parserIndexMemberDeclaration9.errors.txt +++ b/tests/baselines/reference/parserIndexMemberDeclaration9.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration9.ts(2,4): error TS1031: 'export' modifier cannot appear on a class element. +tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration9.ts(2,4): error TS1071: 'export' modifier cannot appear on an index signature. ==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration9.ts (1 errors) ==== class C { export [x: string]: string; ~~~~~~ -!!! error TS1031: 'export' modifier cannot appear on a class element. +!!! error TS1071: 'export' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/parserModifierOnPropertySignature1.errors.txt b/tests/baselines/reference/parserModifierOnPropertySignature1.errors.txt index 4c8750a80c4bc..1ddb9712bf250 100644 --- a/tests/baselines/reference/parserModifierOnPropertySignature1.errors.txt +++ b/tests/baselines/reference/parserModifierOnPropertySignature1.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserModifierOnPropertySignature1.ts(2,5): error TS1131: Property or signature expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserModifierOnPropertySignature1.ts(2,5): error TS1070: 'public' modifier cannot appear on a type member. ==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserModifierOnPropertySignature1.ts (1 errors) ==== interface Foo{ public biz; ~~~~~~ -!!! error TS1131: Property or signature expected. +!!! error TS1070: 'public' modifier cannot appear on a type member. } \ No newline at end of file diff --git a/tests/baselines/reference/parserSymbolIndexer3.errors.txt b/tests/baselines/reference/parserSymbolIndexer3.errors.txt index 5484a096d4ce0..27d3a522b3ea2 100644 --- a/tests/baselines/reference/parserSymbolIndexer3.errors.txt +++ b/tests/baselines/reference/parserSymbolIndexer3.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer3.ts(2,13): error TS1023: An index signature parameter type must be 'string' or 'number'. +tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer3.ts(2,5): error TS1071: 'static' modifier cannot appear on an index signature. ==== tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer3.ts (1 errors) ==== class C { static [s: symbol]: string; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. + ~~~~~~ +!!! error TS1071: 'static' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/privateIndexer.errors.txt b/tests/baselines/reference/privateIndexer.errors.txt index 5d8ae7c935198..5ee21d8e4e30b 100644 --- a/tests/baselines/reference/privateIndexer.errors.txt +++ b/tests/baselines/reference/privateIndexer.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer.ts(4,5): error TS1145: Modifiers not permitted on index signature members. -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer.ts(8,5): error TS1145: Modifiers not permitted on index signature members. -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer.ts(12,5): error TS1145: Modifiers not permitted on index signature members. +tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer.ts(4,5): error TS1071: 'private' modifier cannot appear on an index signature. +tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer.ts(8,5): error TS1071: 'private' modifier cannot appear on an index signature. +tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer.ts(12,5): error TS1071: 'private' modifier cannot appear on an index signature. ==== tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer.ts (3 errors) ==== @@ -9,17 +9,17 @@ tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer.ts(12,5): class C { private [x: string]: string; ~~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'private' modifier cannot appear on an index signature. } class D { private [x: number]: string; ~~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'private' modifier cannot appear on an index signature. } class E { private [x: string]: T; ~~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'private' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/publicIndexer.errors.txt b/tests/baselines/reference/publicIndexer.errors.txt index 860290ea25b3b..29454f2a20863 100644 --- a/tests/baselines/reference/publicIndexer.errors.txt +++ b/tests/baselines/reference/publicIndexer.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/classes/indexMemberDeclarations/publicIndexer.ts(4,5): error TS1145: Modifiers not permitted on index signature members. -tests/cases/conformance/classes/indexMemberDeclarations/publicIndexer.ts(8,5): error TS1145: Modifiers not permitted on index signature members. -tests/cases/conformance/classes/indexMemberDeclarations/publicIndexer.ts(12,5): error TS1145: Modifiers not permitted on index signature members. +tests/cases/conformance/classes/indexMemberDeclarations/publicIndexer.ts(4,5): error TS1071: 'public' modifier cannot appear on an index signature. +tests/cases/conformance/classes/indexMemberDeclarations/publicIndexer.ts(8,5): error TS1071: 'public' modifier cannot appear on an index signature. +tests/cases/conformance/classes/indexMemberDeclarations/publicIndexer.ts(12,5): error TS1071: 'public' modifier cannot appear on an index signature. ==== tests/cases/conformance/classes/indexMemberDeclarations/publicIndexer.ts (3 errors) ==== @@ -9,17 +9,17 @@ tests/cases/conformance/classes/indexMemberDeclarations/publicIndexer.ts(12,5): class C { public [x: string]: string; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'public' modifier cannot appear on an index signature. } class D { public [x: number]: string; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'public' modifier cannot appear on an index signature. } class E { public [x: string]: T; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'public' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/readonlyMembers.errors.txt b/tests/baselines/reference/readonlyMembers.errors.txt new file mode 100644 index 0000000000000..7bc10aa374690 --- /dev/null +++ b/tests/baselines/reference/readonlyMembers.errors.txt @@ -0,0 +1,114 @@ +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 (15 errors) ==== + + interface X { + readonly a: number; + readonly b?: number; + } + 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. + x.b = 1; // Error + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + + class C { + readonly a: number; + readonly b = 1; + get c() { return 1 } + constructor() { + 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. + const f = () => { + this.a = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be 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. + this.c = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be 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. + this.b = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be 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. + } + } + + var o = { + get a() { return 1 }, + get b() { return 1 }, + set b(value) { } + }; + o.a = 1; // Error + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be 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. + p.b = 1; + var q: { a: number, b: number } = p; + q.a = 1; + q.b = 1; + + enum E { + A, B, C + } + E.A = 1; // Error + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + + namespace N { + export const a = 1; + export let b = 1; + 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. + N.b = 1; + N.c = 1; + + let xx: { readonly [x: string]: string }; + 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. + + 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. + yy["foo"] = "abc"; \ No newline at end of file diff --git a/tests/baselines/reference/readonlyMembers.js b/tests/baselines/reference/readonlyMembers.js new file mode 100644 index 0000000000000..899c52d86262c --- /dev/null +++ b/tests/baselines/reference/readonlyMembers.js @@ -0,0 +1,132 @@ +//// [readonlyMembers.ts] + +interface X { + readonly a: number; + readonly b?: number; +} +var x: X = { a: 0 }; +x.a = 1; // Error +x.b = 1; // Error + +class C { + readonly a: number; + readonly b = 1; + get c() { return 1 } + constructor() { + this.a = 1; // Ok + this.b = 1; // Ok + this.c = 1; // Error + const f = () => { + this.a = 1; // Error + this.b = 1; // Error + this.c = 1; // Error + } + } + foo() { + this.a = 1; // Error + this.b = 1; // Error + this.c = 1; // Error + } +} + +var o = { + get a() { return 1 }, + get b() { return 1 }, + set b(value) { } +}; +o.a = 1; // Error +o.b = 1; + +var p: { readonly a: number, b: number } = { a: 1, b: 1 }; +p.a = 1; // Error +p.b = 1; +var q: { a: number, b: number } = p; +q.a = 1; +q.b = 1; + +enum E { + A, B, C +} +E.A = 1; // Error + +namespace N { + export const a = 1; + export let b = 1; + export var c = 1; +} +N.a = 1; // Error +N.b = 1; +N.c = 1; + +let xx: { readonly [x: string]: string }; +let s = xx["foo"]; +xx["foo"] = "abc"; // Error + +let yy: { readonly [x: number]: string, [x: string]: string }; +yy[1] = "abc"; // Error +yy["foo"] = "abc"; + +//// [readonlyMembers.js] +var x = { a: 0 }; +x.a = 1; // Error +x.b = 1; // Error +var C = (function () { + function C() { + var _this = this; + this.b = 1; + this.a = 1; // Ok + this.b = 1; // Ok + this.c = 1; // Error + var f = function () { + _this.a = 1; // Error + _this.b = 1; // Error + _this.c = 1; // Error + }; + } + Object.defineProperty(C.prototype, "c", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + C.prototype.foo = function () { + this.a = 1; // Error + this.b = 1; // Error + this.c = 1; // Error + }; + return C; +}()); +var o = { + get a() { return 1; }, + get b() { return 1; }, + set b(value) { } +}; +o.a = 1; // Error +o.b = 1; +var p = { a: 1, b: 1 }; +p.a = 1; // Error +p.b = 1; +var q = p; +q.a = 1; +q.b = 1; +var E; +(function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; +})(E || (E = {})); +E.A = 1; // Error +var N; +(function (N) { + N.a = 1; + N.b = 1; + N.c = 1; +})(N || (N = {})); +N.a = 1; // Error +N.b = 1; +N.c = 1; +var xx; +var s = xx["foo"]; +xx["foo"] = "abc"; // Error +var yy; +yy[1] = "abc"; // Error +yy["foo"] = "abc"; diff --git a/tests/baselines/reference/redefineArray.errors.txt b/tests/baselines/reference/redefineArray.errors.txt index b0062abff88bf..82ef91807c28b 100644 --- a/tests/baselines/reference/redefineArray.errors.txt +++ b/tests/baselines/reference/redefineArray.errors.txt @@ -1,9 +1,7 @@ -tests/cases/compiler/redefineArray.ts(1,1): error TS2322: Type '(n: number, s: string) => number' is not assignable to type 'ArrayConstructor'. - Property 'isArray' is missing in type '(n: number, s: string) => number'. +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 errors) ==== Array = function (n:number, s:string) {return n;}; ~~~~~ -!!! error TS2322: Type '(n: number, s: string) => number' is not assignable to type 'ArrayConstructor'. -!!! error TS2322: Property 'isArray' is missing in type '(n: number, s: string) => number'. \ No newline at end of file +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/staticAsIdentifier.errors.txt b/tests/baselines/reference/staticAsIdentifier.errors.txt index 52108a5a2214b..4173b0b14c5d3 100644 --- a/tests/baselines/reference/staticAsIdentifier.errors.txt +++ b/tests/baselines/reference/staticAsIdentifier.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/staticAsIdentifier.ts(2,12): error TS1030: 'static' modifier already seen. +tests/cases/compiler/staticAsIdentifier.ts(2,5): error TS1071: 'static' modifier cannot appear on an index signature. ==== tests/cases/compiler/staticAsIdentifier.ts (1 errors) ==== class C { static static - ~~~~~~ -!!! error TS1030: 'static' modifier already seen. + ~~~~~~ +!!! error TS1071: 'static' modifier cannot appear on an index signature. [x: string]: string; } \ No newline at end of file diff --git a/tests/baselines/reference/staticIndexer.errors.txt b/tests/baselines/reference/staticIndexer.errors.txt index 3e91012105116..19ed61df658f3 100644 --- a/tests/baselines/reference/staticIndexer.errors.txt +++ b/tests/baselines/reference/staticIndexer.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/staticIndexer.ts(2,5): error TS1145: Modifiers not permitted on index signature members. +tests/cases/compiler/staticIndexer.ts(2,5): error TS1071: 'static' modifier cannot appear on an index signature. ==== tests/cases/compiler/staticIndexer.ts (1 errors) ==== class C { static [s: string]: number; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'static' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/staticIndexers.errors.txt b/tests/baselines/reference/staticIndexers.errors.txt index 29c46d0ce8c50..8223a38a9ae40 100644 --- a/tests/baselines/reference/staticIndexers.errors.txt +++ b/tests/baselines/reference/staticIndexers.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(4,5): error TS1145: Modifiers not permitted on index signature members. -tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(8,5): error TS1145: Modifiers not permitted on index signature members. -tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(12,5): error TS1145: Modifiers not permitted on index signature members. +tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(4,5): error TS1071: 'static' modifier cannot appear on an index signature. +tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(8,5): error TS1071: 'static' modifier cannot appear on an index signature. +tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(12,5): error TS1071: 'static' modifier cannot appear on an index signature. tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(12,25): error TS2302: Static members cannot reference class type parameters. @@ -10,19 +10,19 @@ tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(12,25) class C { static [x: string]: string; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'static' modifier cannot appear on an index signature. } class D { static [x: number]: string; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'static' modifier cannot appear on an index signature. } class E { static [x: string]: T; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'static' modifier cannot appear on an index signature. ~ !!! error TS2302: Static members cannot reference class type parameters. } \ No newline at end of file diff --git a/tests/baselines/reference/symbolProperty5.types b/tests/baselines/reference/symbolProperty5.types index 4af020dca1ba3..b338f94f6d325 100644 --- a/tests/baselines/reference/symbolProperty5.types +++ b/tests/baselines/reference/symbolProperty5.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/Symbols/symbolProperty5.ts === var x = { ->x : { [Symbol.iterator]: number; [Symbol.toPrimitive](): void; [Symbol.toStringTag]: number; } ->{ [Symbol.iterator]: 0, [Symbol.toPrimitive]() { }, get [Symbol.toStringTag]() { return 0; }} : { [Symbol.iterator]: number; [Symbol.toPrimitive](): void; [Symbol.toStringTag]: number; } +>x : { [Symbol.iterator]: number; [Symbol.toPrimitive](): void; readonly [Symbol.toStringTag]: number; } +>{ [Symbol.iterator]: 0, [Symbol.toPrimitive]() { }, get [Symbol.toStringTag]() { return 0; }} : { [Symbol.iterator]: number; [Symbol.toPrimitive](): void; readonly [Symbol.toStringTag]: number; } [Symbol.iterator]: 0, >Symbol.iterator : symbol diff --git a/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt b/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt index d97d33b010334..d7410ec04cb50 100644 --- a/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt +++ b/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(10,41): error TS2375: Duplicate number index signature. +tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(10,70): error TS2375: Duplicate number index signature. ==== tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts (1 errors) ==== @@ -9,8 +9,8 @@ tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(10,41): error TS2375: Dup b = 1 } var x = E; - var x: { a: E; b: E;[x: number]: string; }; // Shouldnt error + var x: { readonly a: E; readonly b: E; readonly [x: number]: string; }; // Shouldnt error var y = E; - var y: { a: E; b: E;[x: number]: string;[x: number]: string } // two errors: the types are not identical and duplicate signatures - ~~~~~~~~~~~~~~~~~~~ + var y: { readonly a: E; readonly b: E; readonly [x: number]: string; readonly [x: number]: string } // two errors: the types are not identical and duplicate signatures + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2375: Duplicate number index signature. \ No newline at end of file diff --git a/tests/baselines/reference/typeOfEnumAndVarRedeclarations.js b/tests/baselines/reference/typeOfEnumAndVarRedeclarations.js index ce77eac85e62f..391c9c1679a97 100644 --- a/tests/baselines/reference/typeOfEnumAndVarRedeclarations.js +++ b/tests/baselines/reference/typeOfEnumAndVarRedeclarations.js @@ -6,9 +6,9 @@ enum E { b = 1 } var x = E; -var x: { a: E; b: E;[x: number]: string; }; // Shouldnt error +var x: { readonly a: E; readonly b: E; readonly [x: number]: string; }; // Shouldnt error var y = E; -var y: { a: E; b: E;[x: number]: string;[x: number]: string } // two errors: the types are not identical and duplicate signatures +var y: { readonly a: E; readonly b: E; readonly [x: number]: string; readonly [x: number]: string } // two errors: the types are not identical and duplicate signatures //// [typeOfEnumAndVarRedeclarations.js] var E; diff --git a/tests/baselines/reference/validNullAssignments.errors.txt b/tests/baselines/reference/validNullAssignments.errors.txt index 042a7172b5204..057d6ce479198 100644 --- a/tests/baselines/reference/validNullAssignments.errors.txt +++ b/tests/baselines/reference/validNullAssignments.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/primitives/null/validNullAssignments.ts(10,1): error TS2364: Invalid left-hand side of assignment expression. +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(20,1): error TS2304: Cannot find name 'I'. tests/cases/conformance/types/primitives/null/validNullAssignments.ts(23,1): error TS2364: Invalid left-hand side of assignment expression. @@ -17,7 +17,7 @@ tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): err enum E { A } E.A = null; // error ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. class C { foo: string } var f: C; diff --git a/tests/cases/compiler/readonlyMembers.ts b/tests/cases/compiler/readonlyMembers.ts new file mode 100644 index 0000000000000..f24b365772755 --- /dev/null +++ b/tests/cases/compiler/readonlyMembers.ts @@ -0,0 +1,67 @@ +// @target: es5 + +interface X { + readonly a: number; + readonly b?: number; +} +var x: X = { a: 0 }; +x.a = 1; // Error +x.b = 1; // Error + +class C { + readonly a: number; + readonly b = 1; + get c() { return 1 } + constructor() { + this.a = 1; // Ok + this.b = 1; // Ok + this.c = 1; // Error + const f = () => { + this.a = 1; // Error + this.b = 1; // Error + this.c = 1; // Error + } + } + foo() { + this.a = 1; // Error + this.b = 1; // Error + this.c = 1; // Error + } +} + +var o = { + get a() { return 1 }, + get b() { return 1 }, + set b(value) { } +}; +o.a = 1; // Error +o.b = 1; + +var p: { readonly a: number, b: number } = { a: 1, b: 1 }; +p.a = 1; // Error +p.b = 1; +var q: { a: number, b: number } = p; +q.a = 1; +q.b = 1; + +enum E { + A, B, C +} +E.A = 1; // Error + +namespace N { + export const a = 1; + export let b = 1; + export var c = 1; +} +N.a = 1; // Error +N.b = 1; +N.c = 1; + +let xx: { readonly [x: string]: string }; +let s = xx["foo"]; +xx["foo"] = "abc"; // Error + +let yy: { readonly [x: number]: string, [x: string]: string }; +yy[1] = "abc"; // Error +yy["foo"] = "abc"; \ No newline at end of file diff --git a/tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts b/tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts index 996560385d847..2033ef743a4e1 100644 --- a/tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts +++ b/tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts @@ -5,6 +5,6 @@ enum E { b = 1 } var x = E; -var x: { a: E; b: E;[x: number]: string; }; // Shouldnt error +var x: { readonly a: E; readonly b: E; readonly [x: number]: string; }; // Shouldnt error var y = E; -var y: { a: E; b: E;[x: number]: string;[x: number]: string } // two errors: the types are not identical and duplicate signatures \ No newline at end of file +var y: { readonly a: E; readonly b: E; readonly [x: number]: string; readonly [x: number]: string } // two errors: the types are not identical and duplicate signatures \ No newline at end of file diff --git a/tests/cases/conformance/enums/enumBasics.ts b/tests/cases/conformance/enums/enumBasics.ts index 756e08e97afb2..1e134540713b6 100644 --- a/tests/cases/conformance/enums/enumBasics.ts +++ b/tests/cases/conformance/enums/enumBasics.ts @@ -11,10 +11,10 @@ var x: number = E1.A; // Enum object type is anonymous with properties of the enum type and numeric indexer var e = E1; var e: { - A: E1; - B: E1; - C: E1; - [n: number]: string; + readonly A: E1; + readonly B: E1; + readonly C: E1; + readonly [n: number]: string; }; var e: typeof E1; diff --git a/tests/cases/conformance/expressions/objectLiterals/objectLiteralGettersAndSetters.ts b/tests/cases/conformance/expressions/objectLiterals/objectLiteralGettersAndSetters.ts index 5a6bc87af363d..af0622179ac7f 100644 --- a/tests/cases/conformance/expressions/objectLiterals/objectLiteralGettersAndSetters.ts +++ b/tests/cases/conformance/expressions/objectLiterals/objectLiteralGettersAndSetters.ts @@ -16,11 +16,11 @@ var callSig3: { num: (n: number) => string; }; // Get accessor only, type of the property is the annotated return type of the get accessor var getter1 = { get x(): string { return undefined; } }; -var getter1: { x: string; } +var getter1: { readonly x: string; } // Get accessor only, type of the property is the inferred return type of the get accessor var getter2 = { get x() { return ''; } }; -var getter2: { x: string; } +var getter2: { readonly x: string; } // Set accessor only, type of the property is the param type of the set accessor var setter1 = { set x(n: number) { } }; diff --git a/tests/cases/conformance/externalModules/importsImplicitlyReadonly.ts b/tests/cases/conformance/externalModules/importsImplicitlyReadonly.ts new file mode 100644 index 0000000000000..f527606e57624 --- /dev/null +++ b/tests/cases/conformance/externalModules/importsImplicitlyReadonly.ts @@ -0,0 +1,21 @@ +// @module: commonjs + +// @filename: a.ts +export var x = 1; +var y = 1; +export { y }; + +// @filename: b.ts +import { x, y } from "./a"; +import * as a1 from "./a"; +import a2 = require("./a"); +const a3 = a1; + +x = 1; // Error +y = 1; // Error +a1.x = 1; // Error +a1.y = 1; // Error +a2.x = 1; +a2.y = 1; +a3.x = 1; +a3.y = 1; \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoOnObjectLiteralWithOnlyGetter.ts b/tests/cases/fourslash/quickInfoOnObjectLiteralWithOnlyGetter.ts index 53f5e6988b7fe..a2e783d9ce03e 100644 --- a/tests/cases/fourslash/quickInfoOnObjectLiteralWithOnlyGetter.ts +++ b/tests/cases/fourslash/quickInfoOnObjectLiteralWithOnlyGetter.ts @@ -9,7 +9,7 @@ ////var /*2*/x = point./*3*/x; goTo.marker('1'); -verify.quickInfoIs("function makePoint(x: number): {\n x: number;\n}", undefined); +verify.quickInfoIs("function makePoint(x: number): {\n readonly x: number;\n}", undefined); goTo.marker('2'); verify.quickInfoIs("var x: number", undefined); @@ -18,4 +18,4 @@ goTo.marker('3'); verify.memberListContains("x", "(property) x: number", undefined); goTo.marker('4'); -verify.quickInfoIs("var point: {\n x: number;\n}", undefined); +verify.quickInfoIs("var point: {\n readonly x: number;\n}", undefined); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy