I want to create one .d.ts file for one .ts file, without also creating a .js file from my source .ts file.
While there is no compiler for this parameter, we can contain and delete the resulting .js files.
Case 1: One .ts file that does not import local .ts files.
What we can do: 1. appoint . as the declaration directory, 2. designate temp as the JavaScript directory and 3. delete the temp directory after forwarding.
tsc --declaration --declarationDir . --outDir temp foo.ts rm -rf temp
This works if foo.ts does not import other local .ts files. When foo.ts imports other local .ts files, the compiler creates a separate .d.ts file for each. Since this is not what we want right now, itβs better.
Case 2: One .ts file that imports local .ts files
If our use case allows you to create system or amd style declaration files, we can do this:
tsc foo.ts --outFile foo.js --declaration --module system rm -rf foo.js
Result in both cases
Both of these approaches generate the same directory structure with different ad file syntax.
bar bar.ts foo.d.ts <---- a single declaration file foo.ts tsconfig.json
source share