Skip to content

Commit 459481f

Browse files
authored
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
1 parent cdb47e4 commit 459481f

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

packages/jsii-reflect/lib/enum.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class EnumType extends Type {
1818
return this.spec.members.map((m) => new EnumMember(this, m));
1919
}
2020

21-
public isEnumType() {
21+
public isEnumType(): this is EnumType {
2222
return true;
2323
}
2424
}

packages/jsii-reflect/lib/interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ export class InterfaceType extends ReferenceType {
7272
return Object.fromEntries(this._getMethods(inherited, this));
7373
}
7474

75-
public isDataType() {
75+
public isDataType(): this is InterfaceType {
7676
return !!this.spec.datatype;
7777
}
7878

79-
public isInterfaceType() {
79+
public isInterfaceType(): this is InterfaceType {
8080
return true;
8181
}
8282

0 commit comments

Comments
 (0)