Always check index type validity for all types when an error node is present so we always issue an error (#26789)

* Always check index type validity for all types when an error node is present so we always issue an error

* Change type a bit
This commit is contained in:
Wesley Wigham
2018-09-04 16:00:28 -07:00
committed by GitHub
parent ca662419e8
commit 4ac8976750
7 changed files with 68 additions and 2 deletions

View File

@@ -9380,13 +9380,24 @@ namespace ts {
const apparentObjectType = getApparentType(objectType);
if (indexType.flags & TypeFlags.Union && !(indexType.flags & TypeFlags.Boolean)) {
const propTypes: Type[] = [];
let wasMissingProp = false;
for (const t of (<UnionType>indexType).types) {
const propType = getPropertyTypeForIndexType(apparentObjectType, t, accessNode, /*cacheSymbol*/ false, missingType);
if (propType === missingType) {
return missingType;
if (!accessNode) {
// If there's no error node, we can immeditely stop, since error reporting is off
return missingType;
}
else {
// Otherwise we set a flag and return at the end of the loop so we still mark all errors
wasMissingProp = true;
}
}
propTypes.push(propType);
}
if (wasMissingProp) {
return missingType;
}
return getUnionType(propTypes);
}
return getPropertyTypeForIndexType(apparentObjectType, indexType, accessNode, /*cacheSymbol*/ true, missingType);