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 authored and GitHub committed 2021-03-06 06:51:02 -08:00
1 parent 7394efc9be
commit ba56fca0bf
5 files changed
+267 -1

No files matched your search

+2 -1
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) {