jsdoc-type-pratt-parser is a robust library designed for parsing JSDoc type expressions into an Abstract Syntax Tree (AST). It offers support for three distinct grammars: 'jsdoc', 'closure', and 'typescript', allowing it to handle a wide range of type syntaxes. Unlike older parsing solutions such as `catharsis` or `jsdoctypeparser` that might rely on tools like PEG.js, this library is built as a Pratt parser, which is a powerful and flexible approach for handling operator precedence in expressions. The package is actively maintained, with frequent releases (e.g., v7.2.0 released in April 2026), and ships with full TypeScript type definitions. Beyond parsing, it provides utilities for transforming and stringifying ASTs, enabling developers to customize the output based on specific requirements, making it a versatile tool for any project dealing with JSDoc type analysis or manipulation. Its key differentiators include its Pratt parser architecture, explicit grammar support, and comprehensive TypeScript integration.
npm install jsdoc-type-pratt-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates parsing a complex TypeScript-style JSDoc type expression into an AST, inspecting a part of the AST, stringifying it back, and then parsing a JSDoc-specific callback type, showcasing the different grammar options.
Review existing code that relies on `infer` within generic argument lists. Adapt to the new `InferResult` structure at the root level of the AST for infer types.
Always explicitly specify the `grammar` argument in `parse()` based on the syntax of the JSDoc type expression you are processing (e.g., `parse(typeString, 'typescript')`).
Utilize `console.log(JSON.stringify(ast, null, 2))` to pretty-print and inspect the generated AST for specific type expressions, particularly when working with complex or custom type structures.
Ensure you are using ESM `import` statements: `import { parse } from 'jsdoc-type-pratt-parser';`. If in a CommonJS context, Node.js v20+ typically supports dynamic `import()` or ensures your build system correctly transpiles ESM to CJS.Specify the `'typescript'` grammar when parsing type expressions that utilize TypeScript-specific syntax: `parse(typeExpression, 'typescript');`.
First, ensure the package is installed: `npm install jsdoc-type-pratt-parser`. Verify your `tsconfig.json` (for TypeScript) or build configuration allows for correct module resolution, especially for ESM packages.
No dependency data recorded yet.