From 7807ac96f58304e5a6ba979f83005b4e954055e2 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 4 Nov 2016 16:47:43 -0700 Subject: [PATCH] Attach symbols to mapped types --- src/compiler/binder.ts | 3 ++- src/compiler/checker.ts | 7 ++----- src/compiler/types.ts | 3 +-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index e9419ab1cc6..4d923888e86 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1957,9 +1957,10 @@ namespace ts { case SyntaxKind.JSDocFunctionType: return bindFunctionOrConstructorType(node); case SyntaxKind.TypeLiteral: + case SyntaxKind.MappedType: case SyntaxKind.JSDocTypeLiteral: case SyntaxKind.JSDocRecordType: - return bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type"); + return bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type"); case SyntaxKind.ObjectLiteralExpression: return bindObjectLiteralExpression(node); case SyntaxKind.FunctionExpression: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7e87980cf15..afd2b50c871 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5884,10 +5884,8 @@ namespace ts { function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode) { if (indexType.flags & TypeFlags.TypeParameter) { - if (!isTypeAssignableTo(getConstraintOfTypeParameter(indexType) || emptyObjectType, getIndexType(objectType))) { - if (accessNode) { - error(accessNode, Diagnostics.Type_0_is_not_constrained_to_keyof_1, typeToString(indexType), typeToString(objectType)); - } + if (accessNode && !isTypeAssignableTo(getConstraintOfTypeParameter(indexType) || emptyObjectType, getIndexType(objectType))) { + error(accessNode, Diagnostics.Type_0_is_not_constrained_to_keyof_1, typeToString(indexType), typeToString(objectType)); return unknownType; } return getIndexedAccessTypeForTypeParameter(objectType, indexType); @@ -5919,7 +5917,6 @@ namespace ts { const links = getNodeLinks(node); if (!links.resolvedType) { const type = createObjectType(ObjectFlags.Mapped); - type.declaration = node; type.typeParameter = getDeclaredTypeOfTypeParameter(getSymbolOfNode(node.typeParameter)); type.templateType = node.type ? getTypeFromTypeNode(node.type) : anyType; type.aliasSymbol = aliasSymbol; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 36d0d3fd7b9..fcd5b68950b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2497,7 +2497,7 @@ namespace ts { RegularEnum = 0x00000100, // Enum ValueModule = 0x00000200, // Instantiated module NamespaceModule = 0x00000400, // Uninstantiated module - TypeLiteral = 0x00000800, // Type Literal + TypeLiteral = 0x00000800, // Type Literal or mapped type ObjectLiteral = 0x00001000, // Object Literal Method = 0x00002000, // Method Constructor = 0x00004000, // Constructor @@ -2848,7 +2848,6 @@ namespace ts { /* @internal */ export interface MappedType extends ObjectType { - declaration: MappedTypeNode; typeParameter: TypeParameter; templateType: Type; target?: MappedType; // Instantiation target