Registry /
serialization / thrift-parser-typescript
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ThriftLexer
✓ import { ThriftLexer } from 'thrift-parser-typescript'
✗ const ThriftLexer = require('thrift-parser-typescript').ThriftLexer
The package exports ANTLR-generated lexer; use named import for TypeScript/ESM.
ThriftParser
✓ import { ThriftParser } from 'thrift-parser-typescript'
✗ import ThriftParser from 'thrift-parser-typescript'
Default export is not available; only named exports.
ThriftVisitor
✓ import { ThriftVisitor } from 'thrift-parser-typescript'
✗ import { ThriftVisitor } from 'thrift-parser-typescript/dist/ThriftVisitor'
Direct import from dist/ is unnecessary; all exports are at package root.
ThriftListener
✓ import { ThriftListener } from 'thrift-parser-typescript'
✗ const ThriftListener = require('thrift-parser-typescript').ThriftListener
While require works in CJS, import is preferred for TypeScript and ESM.
Parses a Thrift IDL string into an AST and visits it using a custom visitor.
import { ThriftLexer, ThriftParser, ThriftVisitor } from 'thrift-parser-typescript';
const input = `struct User { 1: required string name; 2: optional i32 age; }`;
const chars = new (require('antlr4ts').ANTLRInputStream)(input);
const lexer = new ThriftLexer(chars);
const tokens = new (require('antlr4ts').CommonTokenStream)(lexer);
const parser = new ThriftParser(tokens);
const tree = parser.document();
class MyVisitor extends ThriftVisitor<string> {
visitStruct(ctx: any): string {
return `struct ${ctx.name}`;
}
}
const result = new MyVisitor().visit(tree);
console.log(result);
Errors
Common errors & fixes
Cannot find module 'antlr4ts'
Missing peer dependency antlr4ts.
fixRun 'npm install antlr4ts' in your project.
TypeError: Class extends value undefined is not a constructor or null
Importing ThriftVisitor incorrectly or missing import.
fixUse 'import { ThriftVisitor } from 'thrift-parser-typescript'. Module not found: Can't resolve 'thrift-parser-typescript'
Package not installed or import path incorrect.
fixRun 'npm install thrift-parser-typescript' and check import path.
Cannot read property 'document' of undefined
Parser not instantiated correctly (missing tokens or input).
fixEnsure you create CommonTokenStream and pass to ThriftParser constructor.
Audit
Dependencies
No dependency data recorded yet.