From e4c7ce6302d4fa57eef3ec85fa467c0aaff866be Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 27 May 2021 14:11:51 -0400 Subject: [PATCH 1/2] Added check for modifiersType existing in a mapped type --- util/type.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/util/type.ts b/util/type.ts index 65cb3c1..b7ddfe7 100644 --- a/util/type.ts +++ b/util/type.ts @@ -279,6 +279,10 @@ function isReadonlyPropertyIntersection(type: ts.Type, name: ts.__String, checke }); } +function hasModifiersType(type: ts.Type): type is ts.Type & { modifiersType: ts.Type} { + return 'modifiersType' in type; +} + function isReadonlyPropertyFromMappedType(type: ts.Type, name: ts.__String, checker: ts.TypeChecker): boolean | undefined { if (!isObjectType(type) || !isObjectFlagSet(type, ts.ObjectFlags.Mapped)) return; @@ -286,6 +290,11 @@ function isReadonlyPropertyFromMappedType(type: ts.Type, name: ts.__String, chec // well-known symbols are not affected by mapped types if (declaration.readonlyToken !== undefined && !/^__@[^@]+$/.test(name)) return declaration.readonlyToken.kind !== ts.SyntaxKind.MinusToken; + + if (!hasModifiersType(type)) { + return; + } + return isPropertyReadonlyInType((<{modifiersType: ts.Type}>type).modifiersType, name, checker); } From 4b8dc9a0a9ced8c3e70b721f4c1b89dfd32f4bfa Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 27 May 2021 14:17:03 -0400 Subject: [PATCH 2/2] Unnecessary curly braces --- util/type.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/util/type.ts b/util/type.ts index b7ddfe7..b615410 100644 --- a/util/type.ts +++ b/util/type.ts @@ -291,9 +291,8 @@ function isReadonlyPropertyFromMappedType(type: ts.Type, name: ts.__String, chec if (declaration.readonlyToken !== undefined && !/^__@[^@]+$/.test(name)) return declaration.readonlyToken.kind !== ts.SyntaxKind.MinusToken; - if (!hasModifiersType(type)) { + if (!hasModifiersType(type)) return; - } return isPropertyReadonlyInType((<{modifiersType: ts.Type}>type).modifiersType, name, checker); }