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

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

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));