Skip to content

Commit a885894

Browse files
committed
Infer properties of type {} when argument of a mapped type is incorrect
1 parent 3220ebc commit a885894

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

src/compiler/checker.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10667,29 +10667,27 @@ namespace ts {
1066710667
const optionalMask = target.declaration.questionToken ? 0 : SymbolFlags.Optional;
1066810668
const members = createSymbolTable();
1066910669
for (const prop of properties) {
10670-
const inferredPropType = inferTargetType(getTypeOfSymbol(prop));
10671-
if (!inferredPropType) {
10670+
const propType = getTypeOfSymbol(prop);
10671+
// If any property contains context sensitive functions that have been skipped, the source type
10672+
// is incomplete and we can't infer a meaningful input type.
10673+
if (propType.flags & TypeFlags.ContainsAnyFunctionType) {
1067210674
return undefined;
1067310675
}
1067410676
const inferredProp = createSymbol(SymbolFlags.Property | prop.flags & optionalMask, prop.escapedName);
1067510677
inferredProp.checkFlags = readonlyMask && isReadonlySymbol(prop) ? CheckFlags.Readonly : 0;
1067610678
inferredProp.declarations = prop.declarations;
10677-
inferredProp.type = inferredPropType;
10679+
inferredProp.type = inferTargetType(propType);
1067810680
members.set(prop.escapedName, inferredProp);
1067910681
}
1068010682
if (indexInfo) {
10681-
const inferredIndexType = inferTargetType(indexInfo.type);
10682-
if (!inferredIndexType) {
10683-
return undefined;
10684-
}
10685-
indexInfo = createIndexInfo(inferredIndexType, readonlyMask && indexInfo.isReadonly);
10683+
indexInfo = createIndexInfo(inferTargetType(indexInfo.type), readonlyMask && indexInfo.isReadonly);
1068610684
}
1068710685
return createAnonymousType(undefined, members, emptyArray, emptyArray, indexInfo, undefined);
1068810686

1068910687
function inferTargetType(sourceType: Type): Type {
1069010688
inference.candidates = undefined;
1069110689
inferTypes(inferences, sourceType, templateType);
10692-
return inference.candidates && getUnionType(inference.candidates, /*subtypeReduction*/ true);
10690+
return inference.candidates ? getUnionType(inference.candidates, /*subtypeReduction*/ true) : emptyObjectType;
1069310691
}
1069410692
}
1069510693

0 commit comments

Comments
 (0)