I want to create a single .d.ts
file for a single .ts
file without also creating a .js
file(s) from my source .ts
file(s).
I want to run something like:
$ tsc myFile.ts -d
But have the result be only myFile.ts
's generated .d.ts
file.
Currently, the result is that that file and all of the .ts
files in my project produce their own .js
and .d.ts
files.
My target is es2015
, so the module option should be defaulting to CommonJS (if that matters).
I want to create a single .d.ts file for a single .ts file without also creating a .js file(s) from my source .ts file(s).
While there is no compiler option for that, we can contain and delete the resultant .js files.
What we can do is
.
as the declaration directory,temp
as the JavaScript directory, anddelete the temp
directory after transpiling.
tsc --declaration --declarationDir . --outDir temp foo.ts
rm -rf temp
That works if foo.ts does not import other, local .ts files. When foo.ts does import other, local .ts files, the compiler creates a separate .d.ts file for each. Since that is not what we want right now, what follows is better.
If our use case allows creating system
or amd
style declaration files, we can do this:
tsc foo.ts --outFile foo.js --declaration --module system
rm -rf foo.js
Both of those approaches generate the same directory structure with different declaration file syntax.
bar
bar.ts
foo.d.ts <---- a single declaration file
foo.ts
tsconfig.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With