Skip to content

feat: add Error.isError() to ESNext lib #60788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 6, 2025

Conversation

dirkluijk
Copy link
Contributor

Fixes #60787

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Dec 17, 2024
@dirkluijk dirkluijk changed the title feat: add Error.isError to ESNext lib feat: add Error.isError() to ESNext lib Dec 17, 2024
@Renegade334
Copy link
Contributor

For reference, this is soon to land in Node v24.

@typescript-bot typescript-bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jun 6, 2025
Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the PR to minimize it. I think it's good now, though my pushing to it means I don't have permission to actually approve it.

/**
* Indicates whether the argument provided is a built-in Error instance or not.
*/
isError(error: unknown): error is Error;
Copy link
Contributor

@Renegade334 Renegade334 Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, in the spec, this is not a predicate on satisfying the shape of the Error prototype.

const pseudo = Reflect.construct(Error, [], Object)
Error.prototype.isPrototypeOf(pseudo) // false
'message' in pseudo // false
'name' in pseudo // false
Error.isError(pseudo) // true

By rights, this should really just return a boolean.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It being a predicate was the main reason everyone wanted it....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(okay the realm problem is the real issue but still)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usefulness very much outweighs the downsides, we think.

@github-project-automation github-project-automation bot moved this from Not started to Needs merge in PR Backlog Jun 6, 2025
@jakebailey jakebailey merged commit ffd98c1 into microsoft:main Jun 6, 2025
32 checks passed
@github-project-automation github-project-automation bot moved this from Needs merge to Done in PR Backlog Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add Error.isError() to ESNext lib
5 participants