Skip to content

Commit 7807ac9

Browse files
committed
Attach symbols to mapped types
1 parent ecdb74c commit 7807ac9

3 files changed

Lines changed: 5 additions & 8 deletions

File tree

src/compiler/binder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1957,9 +1957,10 @@ namespace ts {
19571957
case SyntaxKind.JSDocFunctionType:
19581958
return bindFunctionOrConstructorType(<SignatureDeclaration>node);
19591959
case SyntaxKind.TypeLiteral:
1960+
case SyntaxKind.MappedType:
19601961
case SyntaxKind.JSDocTypeLiteral:
19611962
case SyntaxKind.JSDocRecordType:
1962-
return bindAnonymousDeclaration(<TypeLiteralNode>node, SymbolFlags.TypeLiteral, "__type");
1963+
return bindAnonymousDeclaration(<Declaration>node, SymbolFlags.TypeLiteral, "__type");
19631964
case SyntaxKind.ObjectLiteralExpression:
19641965
return bindObjectLiteralExpression(<ObjectLiteralExpression>node);
19651966
case SyntaxKind.FunctionExpression:

src/compiler/checker.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5884,10 +5884,8 @@ namespace ts {
58845884

58855885
function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode) {
58865886
if (indexType.flags & TypeFlags.TypeParameter) {
5887-
if (!isTypeAssignableTo(getConstraintOfTypeParameter(<TypeParameter>indexType) || emptyObjectType, getIndexType(objectType))) {
5888-
if (accessNode) {
5889-
error(accessNode, Diagnostics.Type_0_is_not_constrained_to_keyof_1, typeToString(indexType), typeToString(objectType));
5890-
}
5887+
if (accessNode && !isTypeAssignableTo(getConstraintOfTypeParameter(<TypeParameter>indexType) || emptyObjectType, getIndexType(objectType))) {
5888+
error(accessNode, Diagnostics.Type_0_is_not_constrained_to_keyof_1, typeToString(indexType), typeToString(objectType));
58915889
return unknownType;
58925890
}
58935891
return getIndexedAccessTypeForTypeParameter(objectType, <TypeParameter>indexType);
@@ -5919,7 +5917,6 @@ namespace ts {
59195917
const links = getNodeLinks(node);
59205918
if (!links.resolvedType) {
59215919
const type = <MappedType>createObjectType(ObjectFlags.Mapped);
5922-
type.declaration = node;
59235920
type.typeParameter = getDeclaredTypeOfTypeParameter(getSymbolOfNode(node.typeParameter));
59245921
type.templateType = node.type ? getTypeFromTypeNode(node.type) : anyType;
59255922
type.aliasSymbol = aliasSymbol;

src/compiler/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,7 +2497,7 @@ namespace ts {
24972497
RegularEnum = 0x00000100, // Enum
24982498
ValueModule = 0x00000200, // Instantiated module
24992499
NamespaceModule = 0x00000400, // Uninstantiated module
2500-
TypeLiteral = 0x00000800, // Type Literal
2500+
TypeLiteral = 0x00000800, // Type Literal or mapped type
25012501
ObjectLiteral = 0x00001000, // Object Literal
25022502
Method = 0x00002000, // Method
25032503
Constructor = 0x00004000, // Constructor
@@ -2848,7 +2848,6 @@ namespace ts {
28482848

28492849
/* @internal */
28502850
export interface MappedType extends ObjectType {
2851-
declaration: MappedTypeNode;
28522851
typeParameter: TypeParameter;
28532852
templateType: Type;
28542853
target?: MappedType; // Instantiation target

0 commit comments

Comments
 (0)