diff --git a/packages/pyright-internal/src/analyzer/typedDicts.ts b/packages/pyright-internal/src/analyzer/typedDicts.ts index 21f7ca36d9c5..c2a68cb65282 100644 --- a/packages/pyright-internal/src/analyzer/typedDicts.ts +++ b/packages/pyright-internal/src/analyzer/typedDicts.ts @@ -953,10 +953,9 @@ export function getTypedDictDictEquivalent( let dictValueType = entries.extraItems.valueType; - let isEquivalentToDict = true; - entries.knownItems.forEach((entry) => { + for (const entry of entries.knownItems.values()) { if (entry.isReadOnly || entry.isRequired) { - isEquivalentToDict = false; + return undefined; } dictValueType = combineTypes([dictValueType, entry.valueType]); @@ -971,12 +970,8 @@ export function getTypedDictDictEquivalent( recursionCount + 1 ) ) { - isEquivalentToDict = false; + return undefined; } - }); - - if (!isEquivalentToDict) { - return undefined; } return dictValueType;