Skip to content

Commit 640b5f8

Browse files
ahejlsbergJack-Works
authored andcommitted
No constraint on in T type when as N clause present
1 parent 4c4d824 commit 640b5f8

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10340,9 +10340,6 @@ namespace ts {
1034010340
// bound includes those keys that are known to always be present, for example because
1034110341
// because of constraints on type parameters (e.g. 'keyof T' for a constrained T).
1034210342
function getLowerBoundOfKeyType(type: Type): Type {
10343-
if (type.flags & (TypeFlags.Any | TypeFlags.Primitive)) {
10344-
return type;
10345-
}
1034610343
if (type.flags & TypeFlags.Index) {
1034710344
const t = getApparentType((<IndexType>type).type);
1034810345
return isGenericTupleType(t) ? getKnownKeysOfTupleType(t) : getIndexType(t);
@@ -10363,7 +10360,7 @@ namespace ts {
1036310360
if (type.flags & TypeFlags.Intersection) {
1036410361
return getIntersectionType(sameMap((<UnionType>type).types, getLowerBoundOfKeyType));
1036510362
}
10366-
return neverType;
10363+
return type;
1036710364
}
1036810365

1036910366
/** Resolve the members of a mapped type { [P in K]: T } */
@@ -31397,12 +31394,14 @@ namespace ts {
3139731394
}
3139831395

3139931396
const type = <MappedType>getTypeFromMappedTypeNode(node);
31400-
const constraintType = getConstraintTypeFromMappedType(type);
31401-
checkTypeAssignableTo(constraintType, keyofConstraintType, getEffectiveConstraintOfTypeParameter(node.typeParameter));
3140231397
const nameType = getNameTypeFromMappedType(type);
3140331398
if (nameType) {
3140431399
checkTypeAssignableTo(nameType, keyofConstraintType, node.nameType);
3140531400
}
31401+
else {
31402+
const constraintType = getConstraintTypeFromMappedType(type);
31403+
checkTypeAssignableTo(constraintType, keyofConstraintType, getEffectiveConstraintOfTypeParameter(node.typeParameter));
31404+
}
3140631405
}
3140731406

3140831407
function checkThisType(node: ThisTypeNode) {

0 commit comments

Comments
 (0)