Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit .d.ts for type-only usage of .d.ts files in a project #38146

Open
5 tasks done
julientregoat opened this issue Apr 23, 2020 · 0 comments
Open
5 tasks done

Emit .d.ts for type-only usage of .d.ts files in a project #38146

julientregoat opened this issue Apr 23, 2020 · 0 comments
Labels
Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript

Comments

@julientregoat
Copy link

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants