Make optional properties assignable to string index signatures (#41921)

This commit is contained in:
Andrew Branch authored and GitHub committed 2021-01-07 10:46:55 -08:00
1 parent 35c8df04ad
commit dbba8b358f
6 files changed
+222 -1

No files matched your search

+5 -1
View File
@@ -18609,7 +18609,11 @@ namespace ts {
continue;
}
if (kind === IndexKind.String || isNumericLiteralName(prop.escapedName)) {
const related = isRelatedTo(getTypeOfSymbol(prop), target, reportErrors);
const propType = getTypeOfSymbol(prop);
const type = propType.flags & TypeFlags.Undefined || !(kind === IndexKind.String && prop.flags & SymbolFlags.Optional)
? propType
: getTypeWithFacts(propType, TypeFacts.NEUndefined);
const related = isRelatedTo(type, target, reportErrors);
if (!related) {
if (reportErrors) {
reportError(Diagnostics.Property_0_is_incompatible_with_index_signature, symbolToString(prop));