From c427a46affcccfe98498092bebd1aafd6a18326a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 9 Feb 2022 16:28:54 +0100 Subject: [PATCH] Revert "Cache isWeakType computation" This reverts commit 25a71c4de61f6366ffac080d19685dcb200f42b9. --- src/compiler/checker.ts | 21 +++++++-------------- src/compiler/types.ts | 6 ------ 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cf7f65f37b9d5..b9698d23e8aff 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -20258,22 +20258,15 @@ namespace ts { * and no required properties, call/construct signatures or index signatures */ function isWeakType(type: Type): boolean { - if (!(type.flags & (TypeFlags.Object | TypeFlags.Intersection))) { - return false; + if (type.flags & TypeFlags.Object) { + const resolved = resolveStructuredTypeMembers(type as ObjectType); + return resolved.callSignatures.length === 0 && resolved.constructSignatures.length === 0 && resolved.indexInfos.length === 0 && + resolved.properties.length > 0 && every(resolved.properties, p => !!(p.flags & SymbolFlags.Optional)); } - if (!((type as ObjectType | IntersectionType).objectFlags & ObjectFlags.IsWeakTypeComputed)) { - let isWeak; - if (type.flags & TypeFlags.Object) { - const resolved = resolveStructuredTypeMembers(type as ObjectType); - isWeak = resolved.callSignatures.length === 0 && resolved.constructSignatures.length === 0 && resolved.indexInfos.length === 0 && - resolved.properties.length > 0 && every(resolved.properties, p => !!(p.flags & SymbolFlags.Optional)); - } - else { - isWeak = every((type as IntersectionType).types, isWeakType); - } - (type as ObjectType | IntersectionType).objectFlags |= ObjectFlags.IsWeakTypeComputed | (isWeak ? ObjectFlags.IsWeakType : 0); + if (type.flags & TypeFlags.Intersection) { + return every((type as IntersectionType).types, isWeakType); } - return !!((type as ObjectType | IntersectionType).objectFlags & ObjectFlags.IsWeakType); + return false; } function hasCommonProperties(source: Type, target: Type, isComparingJsxAttributes: boolean) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 05ac24af6e23a..5cabf3edef8be 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5360,12 +5360,6 @@ namespace ts { IsNeverIntersectionComputed = 1 << 25, // IsNeverLike flag has been computed /* @internal */ IsNeverIntersection = 1 << 26, // Intersection reduces to never - - // Flags that require TypeFlags.Object or TypeFlags.Intersection - /* @internal */ - IsWeakTypeComputed = 1 << 27, - /* @internal */ - IsWeakType = 1 << 28, } /* @internal */