fix(typescript): emit declaration files for type-only source files that are not explicitly included #1555
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rollup Plugin Name:
@rollup/plugin-typescript
This PR contains:
Are tests included?
Breaking Changes?
If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.
List any relevant issue numbers:
Description
Please read the linked issue first for context.
The core issue is that TypeScript source files which contain only type definitions transpile into nothing. This means that Rollup has no equivalent JavaScript files to operate on (i.e., we cannot handle these files if they are not already included in
tsconfig.json
because within the Rollup build hooks and output generation hooks, these files do not exist). Specifically in the test case added, theexport
statement inmain.ts
is removed when transpiling into JavaScript becauseMyNumber
is a type. This means that by the time Rollup operates onmain.js
, there is no longer any logical link betweenmain.ts
&should-be-emitted-types.ts
.However, the observation here is that we don't have to manually keep track of which files to emit because the TypeScript compiler already does it for us. Specifically, the TypeScript compiler only emits the files which are necessary (this is verified in the test case I added). This means that we can simply emit all declaration & source map files in
emittedFiles
to solve the linked issue.