-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Description
Search Terms
type only export import declaration declarations .d.ts 3.8
Suggestion
When building code has .d.ts files written and used internally, the declarations aren't emitted. This makes sense currently because .d.ts files aren't compiled. However, it causes typechecking errors when exporting content from the package for external usage, since the declaration isn't included in the compiled output.
import/export type made some initial progress for me by removing the types from the compiled JS output. but I believe it would be even more useful to re emit declarations for type only import exports. this would ensure that ambient declarations are included in the final compiled output.
My issue may be incorrect usage of declaration files, which I've only been using due to the external code generation using it. I'm not sure I explained my idea clearly, but I believe my below examples should cover it - please follow up if not.
Use Cases
I have an existing project that exports declarations generated by an external package from non-JS code. The original code doesn't need to be included, just the types for usage by external consumers. When I want to reexport those declarations, I have to manually copy them over to the build folder after since they disappear. You can see an example of this here
Examples
given directory structure
./src/index.ts
./src/generated.d.ts
and usage
// ./src/index.ts
import type Foo from './generated.d.ts'
the output structure should be
./dist/index.js
./dist/index.d.ts
./dist/generated.d.ts
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.