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

Wrong typescript declaration for errorConstructors #78

Open
ghost opened this issue May 31, 2022 · 6 comments
Open

Wrong typescript declaration for errorConstructors #78

ghost opened this issue May 31, 2022 · 6 comments

Comments

@ghost
Copy link

ghost commented May 31, 2022

Argument of type '(string | SystemError | AssertionError | EvalErrorConstructor | { new (message?: string | undefined, name?: string | undefined): DOMException; ... 25 more ...; readonly WRONG_DOCUMENT_ERR: number; })[][]' is not assignable to parameter of type 'Iterable<readonly [string, ErrorConstructor]>'.
      The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
        Type 'IteratorResult<(string | SystemError | AssertionError | EvalErrorConstructor | { new (message?: string | undefined, name?: string | undefined): DOMException; ... 25 more ...; readonly WRONG_DOCUMENT_ERR: number; })[], any>' is not assignable to type 'IteratorResult<readonly [string, ErrorConstructor], any>'.
          Type 'IteratorYieldResult<(string | SystemError | AssertionError | EvalErrorConstructor | { new (message?: string | undefined, name?: string | undefined): DOMException; ... 25 more ...; readonly WRONG_DOCUMENT_ERR: number; })[]>' is not assignable to type 'IteratorResult<readonly [string, ErrorConstructor], any>'.
            Type 'IteratorYieldResult<(string | SystemError | AssertionError | EvalErrorConstructor | { new (message?: string | undefined, name?: string | undefined): DOMException; ... 25 more ...; readonly WRONG_DOCUMENT_ERR: number; })[]>' is not assignable to type 'IteratorYieldResult<readonly [string, ErrorConstructor]>'.
              Type '(string | SystemError | AssertionError | EvalErrorConstructor | { new (message?: string | undefined, name?: string | undefined): DOMException; ... 25 more ...; readonly WRONG_DOCUMENT_ERR: number; })[]' is not assignable to type 'readonly [string, ErrorConstructor]'.
                Target requires 2 element(s) but source may have fewer.
  Overload 2 of 4, '(entries?: readonly (readonly [string, ErrorConstructor])[] | null | undefined): Map<string, ErrorConstructor>', gave the following error.
    Argument of type '(string | SystemError | AssertionError | EvalErrorConstructor | { new (message?: string | undefined, name?: string | undefined): DOMException; ... 25 more ...; readonly WRONG_DOCUMENT_ERR: number; })[][]' is not assignable to parameter of type 'readonly (readonly [string, ErrorConstructor])[]'.
      Type '(string | SystemError | AssertionError | EvalErrorConstructor | { new (message?: string | undefined, name?: string | undefined): DOMException; ... 25 more ...; readonly WRONG_DOCUMENT_ERR: number; })[]' is not assignable to type 'readonly [string, ErrorConstructor]'.

This message is shown when the code is converted to Typescript.

@ghost ghost mentioned this issue May 31, 2022
@fregante
Copy link
Contributor

fregante commented Jun 1, 2022

Where are you seeing this error? What's your code?

@ghost
Copy link
Author

ghost commented Jun 1, 2022

@fregante I have converted the code to Typescript

https://gist.github.com/ayanamidev/e32ea8edb5c4bd462b04ab30af9465cb

Since the type definitions are written & updated manually, I think the error from typescript compiler makes sense.

@fregante
Copy link
Contributor

fregante commented Jun 8, 2022

I thought I commented here. In short the error doesn't affect the final user, but PR welcome to fix the type to something more generic like new (message: string, ...args: unknown[]): Error. The issue here is that some internal Errors don't match the Error constructor exactly

@fregante
Copy link
Contributor

fregante commented Aug 27, 2022

I'm also having trouble adding my own constructor to this. It seems that:

  • it's picking up the ErrorConstructor interface from @types/node instead of lib.es5
  • Even if MessengerError extends Error, and Error is reported as ErrorConstructor, I still get:

Argument of type 'typeof MessengerError' is not assignable to parameter of type 'ErrorConstructor'.
Type 'typeof MessengerError' provides no match for the signature '(message?: string | undefined): Error'.

Seen in https://github.com/pixiebrix/webext-messenger/blob/0ccfd3b008f5cb4d77bd993361022d041b66dcd8/source/shared.ts#L29-L34

Note: The line seems to work, it's just that the types seem incorrect.

@blackbird91
Copy link

Hi, I updated to the latest version of serialize-error (11.0.0) and the support for ios 13.6 and below is gone. Getting the following error. Looks related to error constructor:

image

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#field_declarations

@fregante
Copy link
Contributor

That's unrelated. You'll just have to use Babel or keep using the older version.

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

2 participants