Types declared in types.d.ts not included in output of tsc --emitDeclarationOnly
See original GitHub issueBug Report
🔎 Search Terms
emitDeclarationOnly allowJs “missing types” “.d.ts file” “declaration file”
🕗 Version & Regression Information
When did you start seeing this bug occur?
Only noticed it just now.
- This is the behavior in every version I tried (
typescript@latest
,typescript@next
,typescript@4.6
), and I reviewed the FAQ for entries about declaration files
⏯ Playground Link
💻 Code
// index.js
function bar () {
return 'baz';
}
/** @returns {BarFn} */
export function foo () {
return bar;
}
// types.d.ts
type BarFn = () => string;
// jsconfig.json
{
"compilerOptions": {
"target": "es2021",
"module": "es2022",
"checkJs": true,
"moduleResolution": "node",
"strictNullChecks": true
},
"include": [
"index.js",
"types.d.ts"
]
}
// package.json
{
"name": "tsc-emitdeclarationonly-js",
"type": "module",
"main": "index.js",
"types": "types/lib/index.d.ts",
"scripts": {
"gentypes": "tsc -p jsconfig.json --noEmit false --declaration --emitDeclarationOnly --outDir types"
},
"devDependencies": {
"typescript": "^4.9.3"
}
}
🙁 Actual behavior
The command tsc -p jsconfig.json --noEmit false --declaration --emitDeclarationOnly --outDir types
generates this types/index.d.ts
:
/** @returns {BarFn} */
export function foo(): BarFn;
which is missing the declaration of BarFn
.
🙂 Expected behavior
I expected the BarFn
declaration to be included in the generated types/index.d.ts
:
/** @returns {BarFn} */
export function foo(): BarFn;
export type BarFn = () => string;
… as indeed it is if I move the declaration from types.d.ts
into index.js
, expressed in JSDoc form:
/** @typedef {() => string} BarFn */
… but I don’t want it there and in JSDoc form, I want it in a types.d.ts
file (visible across my codebase) and in TypeScript form. And included in the generated types/index.d.ts
.
Issue Analytics
- State:
- Created 9 months ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Typescript does not copy d.ts files to build - Stack Overflow
So tsc will not copy your custom types.d.ts file to the output ... The .d.ts files are considered "references" the compiler will not...
Read more >Documentation - Creating .d.ts Files from .js files - TypeScript
Generate d.ts files. " declaration ": true,. // This compiler run should. // only output d.ts files. " emitDeclarationOnly ": true,. // Types...
Read more >TypeScript library tips: Rollup your types! | by Martin Hochel
NOTE: this article will not go through how to configure Rollup or how it ... index.js // (type declaration files emitted by tsc)...
Read more >TypeScript: cannot write file .d.ts because it would overwrite ...
ts files e.g. as part of your include array in tsconfig.json or as part of the tsc arguments, and you're asking TypeScript to...
Read more >Compiler Options - Microsoft Open Source
emitDeclarationOnly. Default: false. Only emit .d.ts files; do not emit .js files. This setting is useful if you're using a transpiler other than...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you had a .d.ts file which you consumed and you published it along with your package, and someone else did the same thing, then you’d have a conflict in the global scope.
In general if you’re hand-authoring something that’s local to your project, it should be in a .ts file, not a .d.ts file.
👋 Hi, I’m the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of this repro running against the nightly TypeScript.
Comment by @gthb
:+1: Compiled
Historical Information
:+1: Compiled