Skip to content
This repository was archived by the owner on Jun 14, 2026. It is now read-only.
This repository was archived by the owner on Jun 14, 2026. It is now read-only.

TypeScript types error as unknown #29

Description

@varanauskas

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions