Skip to content

Commit

Permalink
fix(reflect): additional type predicates for isXyzType methods (#4491)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mrgrain authored Apr 26, 2024
1 parent cdb47e4 commit 459481f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/jsii-reflect/lib/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/jsii-reflect/lib/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 459481f

Please sign in to comment.