TS PEG.js is a TypeScript code generation plugin for peggy parser generator (v3+). Current stable version is 4.2.1, compatible with peggy ^3.0.2. It generates TypeScript parsers from PEG grammars, supporting custom headers, return type annotations, and various options for type computation. Key differentiators: first-class TypeScript output, supports both CommonJS and ESM formats, and integrates seamlessly with peggy's CLI and API. Previously supported pegjs, now exclusively peggy. Notable breaking changes in v3.0.0 include renaming exported interfaces (dropping 'I' prefix) and changing the default error name from SyntaxError to PeggySyntaxError.
npm install ts-pegjsVerified import paths — ran on the pinned version, not inferred.
Generates a TypeScript parser from a simple arithmetic grammar using peggy and ts-pegjs plugin, with return type annotations.
Update code that catches SyntaxError to catch PeggySyntaxError, or set errorName option back to 'SyntaxError'.
Update import statements to use new interface names: ParseOptions, Cached, TraceEvent, EndExpectation, OtherExpectation.
Migrate from pegjs to peggy and update grammars if needed.
Either set skipTypeComputation to false (default) or manually provide all return types via returnTypes.
If your grammar uses camelCase rule names, set doNotCamelCaseTypes: true to preserve original casing.
Ensure all ts-pegjs options are nested under tspegjs: { ... } in the peggy.generate options object.Install peggy instead of pegjs and update import paths.
Run 'npm install peggy' or 'yarn add peggy' to install the required peggy parser.
Use: import peggy from 'peggy'; then peggy.generate(...)
Ensure tspegjs is imported correctly: const tspegjs = require('ts-pegjs'); or import tspegjs from 'ts-pegjs';Use the new names: ParseOptions, Cached, TraceEvent, EndExpectation, OtherExpectation.
Nest options under a 'tspegjs' property: { tspegjs: { customHeader: '...' } }