question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong typescript declaration for errorConstructors

See original GitHub issue
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.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
fregantecommented, 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.

0reactions
fregantecommented, Nov 25, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript errors and how to fix them
Common Errors​​ Below you find a list of common TypeScript errors along with the buggy code and its fixed version.
Read more >
Typescript: Work around type definition error for javascript builtin
I want to use FormData in typescript. Unfortunately, the generated typescript definition files doesn't support a FormData constructor with a Form Element as ......
Read more >
Incorrect types for native errors subtypes · Issue #29943 - GitHub
According to the spec, the constructor functions for the native errors ( RangeError , SyntaxError , etc) have the base Error constructor as ......
Read more >
TypeScript Done Wrong - OpenReplay Blog
I'm declaring it as a function that accepts 2 parameters, the first one potentially being null since I'm going with the “Error-first” pattern ......
Read more >
Error() constructor - JavaScript - MDN Web Docs
When Error is used like a function, that is without new , it will return an Error object. Therefore, a mere call to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found