From 459481f360e911ad6d8b5b5afbcce3b596299d85 Mon Sep 17 00:00:00 2001 From: Momo Kornher Date: Fri, 26 Apr 2024 11:05:40 +0100 Subject: [PATCH] fix(reflect): additional type predicates for `isXyzType` methods (#4491) This helps downstream consumers to not have to add type annotations themselves when using these methods. Before: ```ts function needsInterface(type: reflect.InterfaceType) {} if (type.isInterfaceType()) { needsInterface(type as reflect.InterfaceType); } ``` After: ```ts function needsInterface(type: reflect.InterfaceType) {} if (type.isInterfaceType()) { needsInterface(type); } ``` --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0 --- packages/jsii-reflect/lib/enum.ts | 2 +- packages/jsii-reflect/lib/interface.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/jsii-reflect/lib/enum.ts b/packages/jsii-reflect/lib/enum.ts index ac9c6bbd64..6e4db8eaa0 100644 --- a/packages/jsii-reflect/lib/enum.ts +++ b/packages/jsii-reflect/lib/enum.ts @@ -18,7 +18,7 @@ export class EnumType extends Type { return this.spec.members.map((m) => new EnumMember(this, m)); } - public isEnumType() { + public isEnumType(): this is EnumType { return true; } } diff --git a/packages/jsii-reflect/lib/interface.ts b/packages/jsii-reflect/lib/interface.ts index d02ec2933b..05567cce07 100644 --- a/packages/jsii-reflect/lib/interface.ts +++ b/packages/jsii-reflect/lib/interface.ts @@ -72,11 +72,11 @@ export class InterfaceType extends ReferenceType { return Object.fromEntries(this._getMethods(inherited, this)); } - public isDataType() { + public isDataType(): this is InterfaceType { return !!this.spec.datatype; } - public isInterfaceType() { + public isInterfaceType(): this is InterfaceType { return true; }