Suggestion: "emitDts" option for exporting handwritten declarations #39231
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
"emitDts": true
for exporting handwritten declarationsSearch Terms
emit .d.ts, handwritten declaration files, Project References, outDir
Suggestion
Introduce a tsconfig option
"emitDts": true
that will emit.d.ts
source files into theoutDir
, taking precedence over any.js
-generated.d.ts
files.Use Cases
1. Publishing handwritten declarations
Not everyone has their
outDir
inside their source directory. Not everyone publishes a combined set of source + generated files to npm. It's a common pattern to only publish youroutDir
.The workaround is to have a separate script that copies your handwritten
.d.ts
into youroutDir
, overwriting any unwanted.js
-generated declarations. This is workable but a bit cumbersome for such a common use-case.2. Importing another project's
outDir
Project References allow you to import types a from sibling project's source directory. If instead you switch to import from the sibling project's
outDir
(that is using"declaration": true
), importing handwritten.d.ts
fails because they are not emitted.Why would people link to generated code? Because it helps simulate the experience of importing published code.
You can work-around lack of
"emitDts": true
by writing a build-script that copies the desiredd.ts
into theoutdir
. This works fine fortsc
builds. However for IDEs (using the language service), it doesn't know about the build-script, and so always ignores the hand-written.d.ts
and favours the.js
-generated version. There is no work-around. Even if you overwrite the file in theoutDir
on disk with a build-script, the language service sees the.js
-generated version.Examples
This repo is an example of how importing handwritten
.d.ts
goes wrong today. Build it usingtsc -b
and observe...hiddenBar
because ./lib-src/main.d.ts is being ignored.Checklist
My suggestion meets these guidelines:
Related Issues
Credits: @mheiber @rricard helped create this issue.
The text was updated successfully, but these errors were encountered: