Remove undefined from optional properties when inferring to index signatures (#43086)

* Remove undefined from optional properties when inferring to index signatures

* Add tests
This commit is contained in:
Anders Hejlsberg
2021-03-06 06:51:02 -08:00
committed by GitHub
parent 7394efc9be
commit ba56fca0bf
5 changed files with 267 additions and 1 deletions

View File

@@ -11777,7 +11777,8 @@ namespace ts {
const propTypes: Type[] = [];
for (const prop of getPropertiesOfType(type)) {
if (kind === IndexKind.String || isNumericLiteralName(prop.escapedName)) {
propTypes.push(getTypeOfSymbol(prop));
const propType = getTypeOfSymbol(prop);
propTypes.push(prop.flags & SymbolFlags.Optional ? getTypeWithFacts(propType, TypeFacts.NEUndefined) : propType);
}
}
if (kind === IndexKind.String) {