in operator shouldn't narrow {} originating in unknown (#50610)

* 'in' operator shouldn't narrow {} originating in unknown

* Add regression test
This commit is contained in:
Anders Hejlsberg
2022-09-02 09:30:17 -07:00
committed by GitHub
parent 549e61d0af
commit 854d448e5c
5 changed files with 130 additions and 1 deletions

View File

@@ -25150,7 +25150,7 @@ namespace ts {
function narrowByInKeyword(type: Type, name: __String, assumeTrue: boolean) {
if (type.flags & TypeFlags.Union
|| type.flags & TypeFlags.Object && declaredType !== type
|| type.flags & TypeFlags.Object && declaredType !== type && !(declaredType === unknownType && isEmptyAnonymousObjectType(type))
|| isThisTypeParameter(type)
|| type.flags & TypeFlags.Intersection && every((type as IntersectionType).types, t => t.symbol !== globalThisSymbol)) {
return filterType(type, t => isTypePresencePossible(t, name, assumeTrue));