Simplify non-inferrable property check to rely on propagation

This commit is contained in:
Anders Hejlsberg
2019-04-10 17:05:07 -10:00
parent 411e7144a9
commit 4b813e310c

View File

@@ -14502,16 +14502,10 @@ namespace ts {
}
function createReverseMappedType(source: Type, target: MappedType, constraint: IndexType) {
const properties = getPropertiesOfType(source);
if (properties.length === 0 && !getIndexInfoOfType(source, IndexKind.String)) {
return undefined;
}
// 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.
for (const prop of properties) {
if (getObjectFlags(getTypeOfSymbol(prop)) & ObjectFlags.NonInferrableType) {
return undefined;
}
if (getObjectFlags(source) & ObjectFlags.NonInferrableType || getPropertiesOfType(source).length === 0 && !getIndexInfoOfType(source, IndexKind.String)) {
return undefined;
}
// For arrays and tuples we infer new arrays and tuples where the reverse mapping has been
// applied to the element type(s).