{"id":26476,"library":"thrift-parser-typescript","title":"thrift-parser-typescript","description":"A TypeScript library for parsing Apache Thrift IDL files into an AST. Current stable version is 0.0.5, with irregular releases. It provides a complete ANTLR-based parser for .thrift files and exports the generated visitor, parser, lexer, and listener. This package is one of the few TypeScript-first Thrift parsers, ships its own type definitions, and is suitable for tooling like code generation or linting.","status":"active","version":"0.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/Dup4/thrift-parser-typescript","tags":["javascript","typescript"],"install":[{"cmd":"npm install thrift-parser-typescript","lang":"bash","label":"npm"},{"cmd":"yarn add thrift-parser-typescript","lang":"bash","label":"yarn"},{"cmd":"pnpm add thrift-parser-typescript","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports ANTLR-generated lexer; use named import for TypeScript/ESM.","wrong":"const ThriftLexer = require('thrift-parser-typescript').ThriftLexer","symbol":"ThriftLexer","correct":"import { ThriftLexer } from 'thrift-parser-typescript'"},{"note":"Default export is not available; only named exports.","wrong":"import ThriftParser from 'thrift-parser-typescript'","symbol":"ThriftParser","correct":"import { ThriftParser } from 'thrift-parser-typescript'"},{"note":"Direct import from dist/ is unnecessary; all exports are at package root.","wrong":"import { ThriftVisitor } from 'thrift-parser-typescript/dist/ThriftVisitor'","symbol":"ThriftVisitor","correct":"import { ThriftVisitor } from 'thrift-parser-typescript'"},{"note":"While require works in CJS, import is preferred for TypeScript and ESM.","wrong":"const ThriftListener = require('thrift-parser-typescript').ThriftListener","symbol":"ThriftListener","correct":"import { ThriftListener } from 'thrift-parser-typescript'"}],"quickstart":{"code":"import { ThriftLexer, ThriftParser, ThriftVisitor } from 'thrift-parser-typescript';\n\nconst input = `struct User { 1: required string name; 2: optional i32 age; }`;\nconst chars = new (require('antlr4ts').ANTLRInputStream)(input);\nconst lexer = new ThriftLexer(chars);\nconst tokens = new (require('antlr4ts').CommonTokenStream)(lexer);\nconst parser = new ThriftParser(tokens);\nconst tree = parser.document();\n\nclass MyVisitor extends ThriftVisitor<string> {\n  visitStruct(ctx: any): string {\n    return `struct ${ctx.name}`;\n  }\n}\nconst result = new MyVisitor().visit(tree);\nconsole.log(result);","lang":"typescript","description":"Parses a Thrift IDL string into an AST and visits it using a custom visitor."},"warnings":[{"fix":"Install antlr4ts: npm install antlr4ts","message":"The package requires antlr4ts as a peer dependency; not installing it leads to runtime errors.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Update imports to use root package path.","message":"In v0.0.4, exports were reorganized; ThriftLexer and ThriftParser moved from subpaths to root.","severity":"breaking","affected_versions":"<0.0.4"},{"fix":"Write boilerplate to create the parser pipeline as shown in quickstart.","message":"The package does not export a 'parse' convenience function; users must manually wire ANTLRInputStream, lexer, tokens, and parser.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Use import { ... } from 'thrift-parser-typescript'.","message":"Importing from 'thrift-parser-typescript/dist/*' is deprecated but still works; prefer root imports.","severity":"deprecated","affected_versions":">=0.0.4"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'npm install antlr4ts' in your project.","cause":"Missing peer dependency antlr4ts.","error":"Cannot find module 'antlr4ts'"},{"fix":"Use 'import { ThriftVisitor } from 'thrift-parser-typescript'.","cause":"Importing ThriftVisitor incorrectly or missing import.","error":"TypeError: Class extends value undefined is not a constructor or null"},{"fix":"Run 'npm install thrift-parser-typescript' and check import path.","cause":"Package not installed or import path incorrect.","error":"Module not found: Can't resolve 'thrift-parser-typescript'"},{"fix":"Ensure you create CommonTokenStream and pass to ThriftParser constructor.","cause":"Parser not instantiated correctly (missing tokens or input).","error":"Cannot read property 'document' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}