peggyjs / peggy

Peggy: Parser generator for JavaScript
https://peggyjs.org/
MIT License
964 stars 65 forks source link

How to use a generated parse in TypeScript program #571

Closed evil-shrike closed 1 week ago

evil-shrike commented 1 month ago

Hi. I generated a parser using the online generator, downloaded it as CommonJS. But my project is in TypeScript, so I need a type declaration for the generated file. I'm running this:

npx -p typescript tsc ./parser.js  --declaration --allowJs --emitDeclarationOnly

where parser.js is the generated parser. I'm getting an error: parser.js:1:1 - error TS9005: Declaration emit for this file requires using private name 'peg$SyntaxError'. An explicit type annotation may unblock declaration emit.

1 module.exports = // @generated by Peggy 4.1.1.

Any ideas how to fix?

hildjj commented 1 month ago
hildjj commented 1 week ago

Please re-open this issue if it turns out the suggested approach doesn't work.