Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

Support typescript "extends" and "types" fields #720

@dobesv

Description

@dobesv

Feature request description

In TypeScript you can referenced your dependencies in the extends field, for example:

"extends": "@some/package/tsconfig.base.json"

or just

"extends": "@some/package"

So when processing typescript files we need to look into the tsconfig.json file and if we see an extends key we need to treat that like an import.

Also, in tsconfig.json you can specify a types field which sort of implicitly imports those types into every file, e.g.

"types": ["node", "jest"]

Creates dependencies on @types/node and @types/jest

Example implementation:

const requirePackageName = require('require-package-name');

const tsconfigParser: Parser = (filePath, deps, rootDir) => {
  const content = readFileSync(filePath, {encoding: 'utf8'});
  const foundDeps: string[] = [];
  const tsconfigJson = JSON.parse(content);
  const types = tsconfigJson.compilerOptions?.types;
  if (types) {
    for (const pkg of types) {
      foundDeps.push(`@types/${pkg}`);
    }
  }
  if (tsconfigJson.extends) {
    foundDeps.push(tsconfigJson.extends);
  }
  return foundDeps.map(p => requirePackageName(p)).filter(Boolean);
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions