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

TypeScript types error as unknown #29

Open
varanauskas opened this issue Dec 17, 2021 · 0 comments
Open

TypeScript types error as unknown #29

varanauskas opened this issue Dec 17, 2021 · 0 comments

Comments

@varanauskas
Copy link

When trying to use this library

try {
  return await this.exampleRepository.save(input);
} catch (error) {
  const wrapped = wrapError(error);
  if (wrapped instanceof UniqueViolationError) {
    throw new ExampleAlreadyExists(wrapped);
  }
  throw error;
}

TypeScript complains because error is of type unknown rather than Error

const wrapped = wrapError(error);
                       // ^^^^^
                       // Argument of type 'unknown' is not assignable to parameter of type 'Error'.

Because of changes in TypeScript 4.4
https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/#use-unknown-catch-variables

User needs to cast the error to Error, however, it does not seem that the code would fail if the error were any other type, so perhaps the typescript d.ts can be changed?

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