How to prevent tsc to generate unused declaration files given a single entry file

37 views Asked by At

Given this tsconfig.json

{
  "compilerOptions": {
    "declaration": true,
    "emitDeclarationOnly": true,
    "outDir": "./dist",
    "rootDir": ".",
    "baseUrl": "."
  },
  "include": ["src/index.ts"],
  "exclude": ["node_modules"]
}

Given source files

src/index.ts

import { TEST } from './test'

src/test.ts

export const TEST = 'test';

After I run tsc it generated both /dist/index.d.ts & dist/index.d.ts

Since index.ts didn't re-export anything from test.ts.

I expect the test.d.ts to not be generated since it won't be used given an entry point is src/index.ts;

If this can't be done natively by tsc, Are there any tools I could remove unused .d.ts files in the second step?

0

There are 0 answers