detective-typescript is a utility library designed to extract the static dependencies from TypeScript module source code or its Abstract Syntax Tree (AST). It provides a programmatic API to analyze imports and exports, including support for various TypeScript features like type-only imports, dynamic imports, and JSX syntax. The current stable version is 14.1.1, with releases occurring somewhat regularly to support newer TypeScript versions and Node.js environments, and to address bug fixes and performance improvements. It differentiates itself by offering fine-grained control over dependency extraction through options like `skipTypeImports`, `mixedImports`, and `skipAsyncImports`, making it suitable for tools that need to build dependency graphs or perform static analysis on TypeScript projects. Its dependency extraction mechanism is robust, relying on AST parsing provided by `@typescript-eslint/typescript-estree`, and it is often used by build tools, bundlers, and linters for static code analysis.
npm install detective-typescriptVerified import paths — ran on the pinned version, not inferred.
Demonstrates extracting static and dynamic dependencies from TypeScript code using various options.
Run `npm install typescript` or `yarn add typescript` in your project alongside `detective-typescript`.
Ensure your Node.js environment is version 18 or newer. Update Node.js if necessary.
When calling `detective(sourceCode, { mixedImports: true })`, ensure `mixedImports` is set to `true`.Upgrade to `detective-typescript@14.1.1` or newer to ensure correct handling of these options.
Install TypeScript in your project: `npm install typescript` or `yarn add typescript`.
Update Node.js to version 18 or newer. Ensure your installed `typescript` version (`npm view detective-typescript peerDependencies.typescript`) matches the supported range and can parse your source code.
Use `import detective from 'detective-typescript';` for ESM or `const detective = require('detective-typescript');` for CommonJS.