mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #6532 from Microsoft/readonlyMembers
Readonly properties and index signatures
This commit is contained in:
+266
-211
@@ -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 {
|
||||
(<ResolvedType>type).members = members;
|
||||
(<ResolvedType>type).properties = getNamedMembers(members);
|
||||
(<ResolvedType>type).callSignatures = callSignatures;
|
||||
(<ResolvedType>type).constructSignatures = constructSignatures;
|
||||
if (stringIndexType) (<ResolvedType>type).stringIndexType = stringIndexType;
|
||||
if (numberIndexType) (<ResolvedType>type).numberIndexType = numberIndexType;
|
||||
if (stringIndexInfo) (<ResolvedType>type).stringIndexInfo = stringIndexInfo;
|
||||
if (numberIndexInfo) (<ResolvedType>type).numberIndexInfo = numberIndexInfo;
|
||||
return <ResolvedType>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<T>(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 = <SignatureDeclaration>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 {
|
||||
(<InterfaceTypeWithDeclaredMembers>type).declaredProperties = getNamedMembers(symbol.members);
|
||||
(<InterfaceTypeWithDeclaredMembers>type).declaredCallSignatures = getSignaturesOfSymbol(symbol.members["__call"]);
|
||||
(<InterfaceTypeWithDeclaredMembers>type).declaredConstructSignatures = getSignaturesOfSymbol(symbol.members["__new"]);
|
||||
(<InterfaceTypeWithDeclaredMembers>type).declaredStringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String);
|
||||
(<InterfaceTypeWithDeclaredMembers>type).declaredNumberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number);
|
||||
(<InterfaceTypeWithDeclaredMembers>type).declaredStringIndexInfo = getIndexInfoOfSymbol(symbol, IndexKind.String);
|
||||
(<InterfaceTypeWithDeclaredMembers>type).declaredNumberIndexInfo = getIndexInfoOfSymbol(symbol, IndexKind.Number);
|
||||
}
|
||||
return <InterfaceTypeWithDeclaredMembers>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(<ObjectType>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<any>
|
||||
return type.flags & TypeFlags.Reference && ((<TypeReference>type).target === globalArrayType || (<TypeReference>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 = (<ResolvedType>type).properties;
|
||||
regularType.callSignatures = (<ResolvedType>type).callSignatures;
|
||||
regularType.constructSignatures = (<ResolvedType>type).constructSignatures;
|
||||
regularType.stringIndexType = (<ResolvedType>type).stringIndexType;
|
||||
regularType.numberIndexType = (<ResolvedType>type).numberIndexType;
|
||||
regularType.stringIndexInfo = (<ResolvedType>type).stringIndexInfo;
|
||||
regularType.numberIndexInfo = (<ResolvedType>type).numberIndexInfo;
|
||||
(<FreshObjectLiteralType>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 {
|
||||
@@ -7722,7 +7749,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((<UnionType>type).types, t => getIndexTypeOfStructuredType(t, kind)) : getIndexTypeOfStructuredType(type, kind));
|
||||
return !!(type.flags & TypeFlags.Union ? forEach((<UnionType>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
|
||||
@@ -8217,9 +8244,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) {
|
||||
@@ -8227,7 +8254,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++) {
|
||||
@@ -8243,9 +8270,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;
|
||||
}
|
||||
@@ -8615,7 +8642,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
|
||||
@@ -8982,16 +9009,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.
|
||||
@@ -9250,7 +9279,7 @@ namespace ts {
|
||||
if (type.flags & TypeFlags.ObjectType) {
|
||||
const resolved = resolveStructuredTypeMembers(<ObjectType>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];
|
||||
}
|
||||
}
|
||||
@@ -10624,81 +10653,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 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 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;
|
||||
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 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.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((<ParenthesizedExpression>n).expression);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
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 = (<ElementAccessExpression>n).argumentExpression;
|
||||
const symbol = findSymbol((<ElementAccessExpression>n).expression);
|
||||
if (symbol && index && index.kind === SyntaxKind.StringLiteral) {
|
||||
const name = (<LiteralExpression>index).text;
|
||||
const prop = getPropertyOfType(getTypeOfSymbol(symbol), name);
|
||||
return prop && (prop.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(prop) & NodeFlags.Const) !== 0;
|
||||
}
|
||||
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;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
return isConstVariableReference((<ParenthesizedExpression>n).expression);
|
||||
default:
|
||||
if (isReferenceToReadonlyEntity(node, symbol) || isReferenceThroughNamespaceImport(node)) {
|
||||
error(expr, constantVariableMessage);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isReferenceOrErrorExpression(n)) {
|
||||
error(n, invalidReferenceMessage);
|
||||
return false;
|
||||
else if (node.kind === SyntaxKind.ElementAccessExpression) {
|
||||
if (links.resolvedIndexInfo && links.resolvedIndexInfo.isReadonly) {
|
||||
error(expr, constantVariableMessage);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isConstVariableReference(n)) {
|
||||
error(n, constantVariableMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -10752,7 +10778,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;
|
||||
}
|
||||
@@ -10766,7 +10792,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;
|
||||
}
|
||||
@@ -10957,7 +10983,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;
|
||||
@@ -11139,7 +11165,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
|
||||
@@ -13203,7 +13231,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
|
||||
@@ -13250,7 +13278,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15973,6 +16002,10 @@ namespace ts {
|
||||
}
|
||||
|
||||
anyArrayType = createArrayType(anyType);
|
||||
|
||||
const symbol = getGlobalSymbol("ReadonlyArray", SymbolFlags.Type, /*diagnostic*/ undefined);
|
||||
globalReadonlyArrayType = symbol && <GenericType>getTypeOfGlobalSymbol(symbol, /*arity*/ 1);
|
||||
anyReadonlyArrayType = globalReadonlyArrayType ? createTypeFromGenericGlobalType(globalReadonlyArrayType, [anyType]) : anyArrayType;
|
||||
}
|
||||
|
||||
function createInstantiatedPromiseLikeType(): ObjectType {
|
||||
@@ -16064,9 +16097,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) {
|
||||
@@ -16095,6 +16136,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");
|
||||
}
|
||||
@@ -16116,6 +16160,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");
|
||||
}
|
||||
@@ -16132,6 +16179,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");
|
||||
@@ -16228,6 +16286,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) {
|
||||
@@ -16373,15 +16434,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<TypeNode>): boolean {
|
||||
|
||||
@@ -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
|
||||
},
|
||||
|
||||
+44
-74
@@ -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 = <MethodSignature>createNode(SyntaxKind.MethodSignature, fullStart);
|
||||
setModifiers(method, modifiers);
|
||||
method.name = name;
|
||||
method.questionToken = questionToken;
|
||||
|
||||
@@ -2232,6 +2232,7 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
const property = <PropertySignature>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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
+39
-30
@@ -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,
|
||||
@@ -2075,6 +2077,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
|
||||
@@ -2182,8 +2185,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
|
||||
@@ -2235,8 +2238,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 */
|
||||
@@ -2299,6 +2302,12 @@ namespace ts {
|
||||
Number,
|
||||
}
|
||||
|
||||
export interface IndexInfo {
|
||||
type: Type;
|
||||
isReadonly: boolean;
|
||||
declaration?: SignatureDeclaration;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export interface TypeMapper {
|
||||
(t: TypeParameter): Type;
|
||||
|
||||
@@ -1592,6 +1592,7 @@ namespace ts {
|
||||
case SyntaxKind.PublicKeyword:
|
||||
case SyntaxKind.PrivateKeyword:
|
||||
case SyntaxKind.ProtectedKeyword:
|
||||
case SyntaxKind.ReadonlyKeyword:
|
||||
case SyntaxKind.StaticKeyword:
|
||||
return true;
|
||||
}
|
||||
@@ -2323,6 +2324,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;
|
||||
}
|
||||
|
||||
Vendored
+238
-150
File diff suppressed because it is too large
Load Diff
Vendored
+50
-48
@@ -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<T> extends Iterator<T> {
|
||||
}
|
||||
|
||||
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<K, V> {
|
||||
has(key: K): boolean;
|
||||
keys(): IterableIterator<K>;
|
||||
set(key: K, value?: V): Map<K, V>;
|
||||
size: number;
|
||||
readonly size: number;
|
||||
values(): IterableIterator<V>;
|
||||
[Symbol.iterator]():IterableIterator<[K,V]>;
|
||||
[Symbol.toStringTag]: "Map";
|
||||
readonly [Symbol.toStringTag]: "Map";
|
||||
}
|
||||
|
||||
interface MapConstructor {
|
||||
new (): Map<any, any>;
|
||||
new <K, V>(): Map<K, V>;
|
||||
new <K, V>(iterable: Iterable<[K, V]>): Map<K, V>;
|
||||
prototype: Map<any, any>;
|
||||
readonly prototype: Map<any, any>;
|
||||
}
|
||||
declare var Map: MapConstructor;
|
||||
|
||||
interface WeakMap<K, V> {
|
||||
clear(): void;
|
||||
delete(key: K): boolean;
|
||||
get(key: K): V;
|
||||
has(key: K): boolean;
|
||||
set(key: K, value?: V): WeakMap<K, V>;
|
||||
[Symbol.toStringTag]: "WeakMap";
|
||||
readonly [Symbol.toStringTag]: "WeakMap";
|
||||
}
|
||||
|
||||
interface WeakMapConstructor {
|
||||
new (): WeakMap<any, any>;
|
||||
new <K, V>(): WeakMap<K, V>;
|
||||
new <K, V>(iterable: Iterable<[K, V]>): WeakMap<K, V>;
|
||||
prototype: WeakMap<any, any>;
|
||||
readonly prototype: WeakMap<any, any>;
|
||||
}
|
||||
declare var WeakMap: WeakMapConstructor;
|
||||
|
||||
@@ -842,37 +843,38 @@ interface Set<T> {
|
||||
forEach(callbackfn: (value: T, index: T, set: Set<T>) => void, thisArg?: any): void;
|
||||
has(value: T): boolean;
|
||||
keys(): IterableIterator<T>;
|
||||
size: number;
|
||||
readonly size: number;
|
||||
values(): IterableIterator<T>;
|
||||
[Symbol.iterator]():IterableIterator<T>;
|
||||
[Symbol.toStringTag]: "Set";
|
||||
readonly [Symbol.toStringTag]: "Set";
|
||||
}
|
||||
|
||||
interface SetConstructor {
|
||||
new (): Set<any>;
|
||||
new <T>(): Set<T>;
|
||||
new <T>(iterable: Iterable<T>): Set<T>;
|
||||
prototype: Set<any>;
|
||||
readonly prototype: Set<any>;
|
||||
}
|
||||
declare var Set: SetConstructor;
|
||||
|
||||
interface WeakSet<T> {
|
||||
add(value: T): WeakSet<T>;
|
||||
clear(): void;
|
||||
delete(value: T): boolean;
|
||||
has(value: T): boolean;
|
||||
[Symbol.toStringTag]: "WeakSet";
|
||||
readonly [Symbol.toStringTag]: "WeakSet";
|
||||
}
|
||||
|
||||
interface WeakSetConstructor {
|
||||
new (): WeakSet<any>;
|
||||
new <T>(): WeakSet<T>;
|
||||
new <T>(iterable: Iterable<T>): WeakSet<T>;
|
||||
prototype: WeakSet<any>;
|
||||
readonly prototype: WeakSet<any>;
|
||||
}
|
||||
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<number>;
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
[Symbol.toStringTag]: "Int8Array";
|
||||
readonly [Symbol.toStringTag]: "Int8Array";
|
||||
}
|
||||
|
||||
interface Int8ArrayConstructor {
|
||||
@@ -940,7 +942,7 @@ interface Uint8Array {
|
||||
*/
|
||||
values(): IterableIterator<number>;
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
[Symbol.toStringTag]: "UInt8Array";
|
||||
readonly [Symbol.toStringTag]: "UInt8Array";
|
||||
}
|
||||
|
||||
interface Uint8ArrayConstructor {
|
||||
@@ -976,7 +978,7 @@ interface Uint8ClampedArray {
|
||||
values(): IterableIterator<number>;
|
||||
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
[Symbol.toStringTag]: "Uint8ClampedArray";
|
||||
readonly [Symbol.toStringTag]: "Uint8ClampedArray";
|
||||
}
|
||||
|
||||
interface Uint8ClampedArrayConstructor {
|
||||
@@ -1014,7 +1016,7 @@ interface Int16Array {
|
||||
|
||||
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
[Symbol.toStringTag]: "Int16Array";
|
||||
readonly [Symbol.toStringTag]: "Int16Array";
|
||||
}
|
||||
|
||||
interface Int16ArrayConstructor {
|
||||
@@ -1047,7 +1049,7 @@ interface Uint16Array {
|
||||
*/
|
||||
values(): IterableIterator<number>;
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
[Symbol.toStringTag]: "Uint16Array";
|
||||
readonly [Symbol.toStringTag]: "Uint16Array";
|
||||
}
|
||||
|
||||
interface Uint16ArrayConstructor {
|
||||
@@ -1080,7 +1082,7 @@ interface Int32Array {
|
||||
*/
|
||||
values(): IterableIterator<number>;
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
[Symbol.toStringTag]: "Int32Array";
|
||||
readonly [Symbol.toStringTag]: "Int32Array";
|
||||
}
|
||||
|
||||
interface Int32ArrayConstructor {
|
||||
@@ -1113,7 +1115,7 @@ interface Uint32Array {
|
||||
*/
|
||||
values(): IterableIterator<number>;
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
[Symbol.toStringTag]: "Uint32Array";
|
||||
readonly [Symbol.toStringTag]: "Uint32Array";
|
||||
}
|
||||
|
||||
interface Uint32ArrayConstructor {
|
||||
@@ -1146,7 +1148,7 @@ interface Float32Array {
|
||||
*/
|
||||
values(): IterableIterator<number>;
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
[Symbol.toStringTag]: "Float32Array";
|
||||
readonly [Symbol.toStringTag]: "Float32Array";
|
||||
}
|
||||
|
||||
interface Float32ArrayConstructor {
|
||||
@@ -1179,7 +1181,7 @@ interface Float64Array {
|
||||
*/
|
||||
values(): IterableIterator<number>;
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
[Symbol.toStringTag]: "Float64Array";
|
||||
readonly [Symbol.toStringTag]: "Float64Array";
|
||||
}
|
||||
|
||||
interface Float64ArrayConstructor {
|
||||
@@ -1256,14 +1258,14 @@ interface Promise<T> {
|
||||
catch(onrejected?: (reason: any) => T | PromiseLike<T>): Promise<T>;
|
||||
catch(onrejected?: (reason: any) => void): Promise<T>;
|
||||
|
||||
[Symbol.toStringTag]: "Promise";
|
||||
readonly [Symbol.toStringTag]: "Promise";
|
||||
}
|
||||
|
||||
interface PromiseConstructor {
|
||||
/**
|
||||
* A reference to the prototype.
|
||||
*/
|
||||
prototype: Promise<any>;
|
||||
readonly prototype: Promise<any>;
|
||||
|
||||
/**
|
||||
* Creates a new Promise.
|
||||
@@ -1325,7 +1327,7 @@ interface PromiseConstructor {
|
||||
*/
|
||||
resolve(): Promise<void>;
|
||||
|
||||
[Symbol.species]: Function;
|
||||
readonly [Symbol.species]: Function;
|
||||
}
|
||||
|
||||
declare var Promise: PromiseConstructor;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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 [<any>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 [<any>true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { readonly [0]: number; [""]: any; }
|
||||
|
||||
get [s]() { return 0; },
|
||||
>s : string
|
||||
|
||||
@@ -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 [<any>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 [<any>true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { readonly [0]: number; [""]: any; }
|
||||
|
||||
get [s]() { return 0; },
|
||||
>s : string
|
||||
|
||||
@@ -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.
|
||||
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property.
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;) { }
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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]--;
|
||||
~~~~~~~~
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
};
|
||||
|
||||
@@ -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"'.
|
||||
|
||||
@@ -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.
|
||||
!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property.
|
||||
@@ -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 };
|
||||
|
||||
@@ -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;
|
||||
@@ -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.
|
||||
!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property.
|
||||
@@ -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.
|
||||
}
|
||||
@@ -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<T> {
|
||||
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.
|
||||
!!! error TS1070: 'private' modifier cannot appear on a type member.
|
||||
}
|
||||
@@ -17,4 +17,3 @@ var x: {
|
||||
//// [interfaceWithPrivateMember.js]
|
||||
// interfaces do not permit private members, these are errors
|
||||
var x;
|
||||
y: string;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
@@ -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) { } };
|
||||
|
||||
@@ -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) { } };
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
@@ -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.
|
||||
}
|
||||
@@ -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.
|
||||
}
|
||||
@@ -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.
|
||||
}
|
||||
@@ -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.
|
||||
}
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
@@ -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<T> {
|
||||
private [x: string]: T;
|
||||
~~~~~~~
|
||||
!!! error TS1145: Modifiers not permitted on index signature members.
|
||||
!!! error TS1071: 'private' modifier cannot appear on an index signature.
|
||||
}
|
||||
@@ -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<T> {
|
||||
public [x: string]: T;
|
||||
~~~~~~
|
||||
!!! error TS1145: Modifiers not permitted on index signature members.
|
||||
!!! error TS1071: 'public' modifier cannot appear on an index signature.
|
||||
}
|
||||
@@ -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";
|
||||
@@ -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";
|
||||
@@ -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'.
|
||||
!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property.
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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.
|
||||
}
|
||||
@@ -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<T> {
|
||||
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.
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
@@ -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
|
||||
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
|
||||
@@ -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;
|
||||
|
||||
|
||||
+2
-2
@@ -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) { } };
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user