Attach symbols to mapped types

This commit is contained in:
Anders Hejlsberg
2016-11-04 16:47:43 -07:00
parent ecdb74cee6
commit 7807ac96f5
3 changed files with 5 additions and 8 deletions

View File

@@ -1957,9 +1957,10 @@ namespace ts {
case SyntaxKind.JSDocFunctionType:
return bindFunctionOrConstructorType(<SignatureDeclaration>node);
case SyntaxKind.TypeLiteral:
case SyntaxKind.MappedType:
case SyntaxKind.JSDocTypeLiteral:
case SyntaxKind.JSDocRecordType:
return bindAnonymousDeclaration(<TypeLiteralNode>node, SymbolFlags.TypeLiteral, "__type");
return bindAnonymousDeclaration(<Declaration>node, SymbolFlags.TypeLiteral, "__type");
case SyntaxKind.ObjectLiteralExpression:
return bindObjectLiteralExpression(<ObjectLiteralExpression>node);
case SyntaxKind.FunctionExpression:

View File

@@ -5884,10 +5884,8 @@ namespace ts {
function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode) {
if (indexType.flags & TypeFlags.TypeParameter) {
if (!isTypeAssignableTo(getConstraintOfTypeParameter(<TypeParameter>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(<TypeParameter>indexType) || emptyObjectType, getIndexType(objectType))) {
error(accessNode, Diagnostics.Type_0_is_not_constrained_to_keyof_1, typeToString(indexType), typeToString(objectType));
return unknownType;
}
return getIndexedAccessTypeForTypeParameter(objectType, <TypeParameter>indexType);
@@ -5919,7 +5917,6 @@ namespace ts {
const links = getNodeLinks(node);
if (!links.resolvedType) {
const type = <MappedType>createObjectType(ObjectFlags.Mapped);
type.declaration = node;
type.typeParameter = getDeclaredTypeOfTypeParameter(getSymbolOfNode(node.typeParameter));
type.templateType = node.type ? getTypeFromTypeNode(node.type) : anyType;
type.aliasSymbol = aliasSymbol;

View File

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