Skip to content
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

Improve extending Custom errors #54

Open
carnakovic opened this issue Sep 16, 2024 · 0 comments
Open

Improve extending Custom errors #54

carnakovic opened this issue Sep 16, 2024 · 0 comments

Comments

@carnakovic
Copy link

Narrowing the error type with instaceof doesn't work correctly.

import { retry, RetryError } from 'ts-retry-promise';

try {
  await retry(() => Promise.reject('test'));
} catch (error: unknown) {
  if (error instanceof RetryError) {
    // never get here
  }

  // the above doesn't work
  error.name // Error
  error instanceof Error // true
  error instanceof RetryError // false
}

Extending built-in Error type with extends ES6 keyword doesn't work correctly when the code is later transformed to ES5.

Recommend to use make-error lib for extending error types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant