Infer properties of type {} when argument of a mapped type is incorrect
This commit is contained in:
parent
3220ebc182
commit
a885894baa
1 changed files with 7 additions and 9 deletions
|
@ -10667,29 +10667,27 @@ namespace ts {
|
||||||
const optionalMask = target.declaration.questionToken ? 0 : SymbolFlags.Optional;
|
const optionalMask = target.declaration.questionToken ? 0 : SymbolFlags.Optional;
|
||||||
const members = createSymbolTable();
|
const members = createSymbolTable();
|
||||||
for (const prop of properties) {
|
for (const prop of properties) {
|
||||||
const inferredPropType = inferTargetType(getTypeOfSymbol(prop));
|
const propType = getTypeOfSymbol(prop);
|
||||||
if (!inferredPropType) {
|
// If any property contains context sensitive functions that have been skipped, the source type
|
||||||
|
// is incomplete and we can't infer a meaningful input type.
|
||||||
|
if (propType.flags & TypeFlags.ContainsAnyFunctionType) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
const inferredProp = createSymbol(SymbolFlags.Property | prop.flags & optionalMask, prop.escapedName);
|
const inferredProp = createSymbol(SymbolFlags.Property | prop.flags & optionalMask, prop.escapedName);
|
||||||
inferredProp.checkFlags = readonlyMask && isReadonlySymbol(prop) ? CheckFlags.Readonly : 0;
|
inferredProp.checkFlags = readonlyMask && isReadonlySymbol(prop) ? CheckFlags.Readonly : 0;
|
||||||
inferredProp.declarations = prop.declarations;
|
inferredProp.declarations = prop.declarations;
|
||||||
inferredProp.type = inferredPropType;
|
inferredProp.type = inferTargetType(propType);
|
||||||
members.set(prop.escapedName, inferredProp);
|
members.set(prop.escapedName, inferredProp);
|
||||||
}
|
}
|
||||||
if (indexInfo) {
|
if (indexInfo) {
|
||||||
const inferredIndexType = inferTargetType(indexInfo.type);
|
indexInfo = createIndexInfo(inferTargetType(indexInfo.type), readonlyMask && indexInfo.isReadonly);
|
||||||
if (!inferredIndexType) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
indexInfo = createIndexInfo(inferredIndexType, readonlyMask && indexInfo.isReadonly);
|
|
||||||
}
|
}
|
||||||
return createAnonymousType(undefined, members, emptyArray, emptyArray, indexInfo, undefined);
|
return createAnonymousType(undefined, members, emptyArray, emptyArray, indexInfo, undefined);
|
||||||
|
|
||||||
function inferTargetType(sourceType: Type): Type {
|
function inferTargetType(sourceType: Type): Type {
|
||||||
inference.candidates = undefined;
|
inference.candidates = undefined;
|
||||||
inferTypes(inferences, sourceType, templateType);
|
inferTypes(inferences, sourceType, templateType);
|
||||||
return inference.candidates && getUnionType(inference.candidates, /*subtypeReduction*/ true);
|
return inference.candidates ? getUnionType(inference.candidates, /*subtypeReduction*/ true) : emptyObjectType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue