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

Using instanceof SyntaxError does not work with TypeScript #216

Closed
cmfcmf opened this issue Nov 22, 2021 · 0 comments · Fixed by #217
Closed

Using instanceof SyntaxError does not work with TypeScript #216

cmfcmf opened this issue Nov 22, 2021 · 0 comments · Fixed by #217
Labels
blocks-release Blocks an imminent release. High Priorty.

Comments

@cmfcmf
Copy link
Contributor

cmfcmf commented Nov 22, 2021

The following code produces an error in TypeScript:

import peggy from "peggy";

const myParser = peggy.generate(`
  Integer "integer"
    = [0-9]+
`);

try {
  myParser.parse("invalid input");
} catch (err) {
  // ERROR: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.ts(2359)
  if (err instanceof myParser.SyntaxError) {
    console.log("It is a SyntaxError");
  }
}

(https://codesandbox.io/s/xenodochial-liskov-kmcyk?file=/src/index.ts)

The code reaches the console.log statement, i.e. the JS runs correctly. However, Typescript complains that I cannot use myParser.SyntaxError on the right hand side of the instanceof check. I tried to investigate this, but couldn't figure out why it happens. Something must be wrong with the type definitions (tested on TypeScript 4.4.4).

cmfcmf added a commit to cmfcmf/peggy that referenced this issue Nov 22, 2021
cmfcmf added a commit to cmfcmf/peggy that referenced this issue Nov 22, 2021
@hildjj hildjj added the blocks-release Blocks an imminent release. High Priorty. label Nov 23, 2021
@hildjj hildjj closed this as completed in ccab5b5 May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocks-release Blocks an imminent release. High Priorty.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants