-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
export default type #41409
Comments
I often want to export values which double as types. For instance. export const Tag = Symbol.for("@my-app/entry.Tag");
export type Tag = typeof Tag; It feels to me like this should be possible with default exports as well. |
Any updates on this? |
TypeScript 5.0 (in #52203) introduced a new option called type X = number | string;
export default X; And a workaround is to mark type X = number | string;
export type {X as default}; // or export {type X as default}; But that looks fairly indirect. Having |
was:type SomePayload = {
data1: number;
data2: string;
};
export default SomePayload; import type SomePayload from './SomePayload.type' now:export type SomePayload = {
data1: number;
data2: string;
}; import type { SomePayload } from './SomePayload.type' seems like a bug, because I have 1 type in 1 file |
unfortunately not working with export default - see here: microsoft/TypeScript#41409
For those who were looking for "Type annotations for |
Search Terms
export default type
Suggestion
Allow
export default
fortype
.Use Cases
It would be very nice to have
export default type
to match with other default exports such as classes and interfaces.Right now it looks very inconsistent to be able to export anything as default and only types with named export:
The only way to achieve this now is to use annoying workaround:
This may cause confusion for newbies as there are no clear reasons why classes and interfaces can be exported as default, but not the types.
Examples
Checklist
My suggestion meets these guidelines:
(not sure on the last)
The text was updated successfully, but these errors were encountered: