ts-api-utils is a utility library providing helper functions for interacting with the TypeScript Compiler API. It serves as a modern successor to the widely used tsutils library, offering improved maintainability and updated conventions. The current stable version is 2.5.0, with a v3.0.0 release candidate recently published, indicating an active development cadence with regular updates. This library is crucial for tooling developers, static analysis tools, and code transformers that need to navigate and analyze TypeScript's Abstract Syntax Tree (AST) and type system. It aims to simplify common operations, making it easier to work with `ts.Node`, `ts.Type`, and `ts.Symbol` objects without directly reimplementing frequently needed logic. Its focus on providing a robust set of utilities for advanced TypeScript usage differentiates it from general-purpose utility libraries.
npm install ts-api-utilsVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing a TypeScript file and using `ts-api-utils` type guards (`isIdentifier`, `isCallExpression`) to analyze its Abstract Syntax Tree (AST).
Upgrade your Node.js environment to 18.12 or higher and ensure `typescript` peer dependency is at least 4.8.4. For older environments, use `ts-api-utils` v1.x.
Review usages of `isTypeParameter` and ensure explicit type checks or assertions are used if strict type narrowing is required. This was a corrective fix to align its behavior more accurately with TypeScript's type system.
Use `import ... from 'ts-api-utils'` syntax. If using CommonJS, ensure your build setup correctly transpiles or handles ESM imports, or upgrade to a modern Node.js version that supports ESM.
Switch to `import { ... } from 'ts-api-utils'` syntax in an ES Module project, or configure Node.js to interpret your files as ESM (e.g., by setting `"type": "module"` in `package.json`).Install `typescript` as a dev dependency with a version compatible with `ts-api-utils` (e.g., `npm install typescript@^5 --save-dev`). Check `ts-api-utils` documentation for exact peer dependency ranges.
Ensure the argument passed to utility functions like `isIdentifier` or `getAccessKind` is a valid `ts.Node` or compatible TypeScript API object. Review the function's signature for expected parameter types.