Repository navigation
[api] Add type.isClass() predicate guard - #65584
Closed
Andrew Branch (andrewbranch) wants to merge 1 commit into
Closed
Andrew Branch (andrewbranch) wants to merge 1 commit into
Andrew Branch (andrewbranch) wants to merge 1 commit into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the async and sync Type.isClass() API additions.
No open issues 🎉
What changed in this PR
Adds Type.isClass() to the TypeScript JavaScript API, allowing callers to identify originating class types and narrow them to InterfaceType.
Changes:
- Adds the type guard and documentation to both async and sync APIs.
- Adds tests covering classes, interfaces, generic specializations, constructors, ordinary values, and type narrowing.
| File | Description |
|---|---|
packages/typescript/test/sync/api.test.ts |
Tests synchronous class detection and type narrowing. |
packages/typescript/test/async/api.test.ts |
Tests asynchronous class detection and type narrowing. |
packages/typescript/src/api/sync/types.ts |
Declares and documents the sync type guard. |
packages/typescript/src/api/sync/api.ts |
Implements sync class detection using object flags. |
packages/typescript/src/api/async/types.ts |
Declares and documents the async type guard. |
packages/typescript/src/api/async/api.ts |
Implements async class detection using object flags. |
Review effort: Balanced
type.isClass() predicate guard
Andrew Branch (andrewbranch)
marked this pull request as ready for review
November 19, 2026 19:50
Member
Author
|
This is an exact copy from Strada, but because class types and interface types are both declare let type: InterfaceType | UnionType;
if (!type.isClass()) {
type; // UnionType - wrong, could be a non-classy interface
}I think it's worth fixing that mistake from the old API and just excluding this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found by #64749