GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — export default type · Issue #41409 · microsoft/TypeScript

export default type #41409

New issue
Copy link
New issue
Copy link
Open
Open
export default type#41409
Copy link
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript

Description

@hopeless-programmer-online
Hopeless Programmer (hopeless-programmer-online)
opened on Nov 5, 2020
Issue body actions

Search Terms

export default type

Suggestion

Allow export default for type.

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:

export default class MyClass {}
export default interface MyInterface {}
export type MyType = {}

The only way to achieve this now is to use annoying workaround:

type X = number | string

export { X as default }

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

// x.ts
export default type X = {}

// main.ts
import X from './x'

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.

(not sure on the last)

Reacted by somerandomdev49, Jayden Seric, Sam Reid, Michael Kauzmann, nai 🖤, whzx5byb, Dmitriy Zasukha, Tim Peko, Joshua Turner, Dannii Willis and 33 more
Reacted by Gerrit Birkeland, Martin Johns, Pau Colomé and Mr. Binary Sniper
Reacted by silverwind

Activity

  1. Daniel Rosenwasser (DanielRosenwasser)
    added
    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this feature
    SuggestionAn idea for TypeScriptAn idea for TypeScript
    on Nov 9, 2020
  2. harrysolovay commented on Dec 3, 2020

    @harrysolovay
    Harry Solovay (harrysolovay)
    on Dec 3, 2020
    More actions

    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.

    Reacted by Hopeless Programmer, John Louderback, Jóhann Guðmundsson, Tim Peko, JongHan Leem, ptrxyz and Gouvernathor
  3. hopeless-programmer-online commented on Apr 16, 2021

    @hopeless-programmer-online
    Hopeless Programmer (hopeless-programmer-online)
    on Apr 16, 2021
    Author
    More actions

    Any updates on this?

    Reacted by John Louderback, Michael Kauzmann, Jóhann Guðmundsson, Dmitriy Zasukha, Tim Peko, Thundercraft5, AlexeiA, Henderson Pinto, MetaCrawler, Victorien Elvinger and 9 more
    Reacted by Henrique Silvério, Marek Legris and Martin Rabaud
  4. PolariTOON commented on Mar 28, 2023

    @PolariTOON
    PolariTOON
    on Mar 28, 2023
    More actions

    TypeScript 5.0 (in #52203) introduced a new option called --verbatimModuleSyntax that makes the following code produce the following error: An 'export default' must reference a value when 'verbatimModuleSyntax' is enabled, but 'X' only refers to a type., because the default export X is not clearly marked as a type:

    type X = number | string;
    export default X;

    And a workaround is to mark X as a type in the export declaration by using a named export:

    type X = number | string;
    export type {X as default}; // or export {type X as default};

    But that looks fairly indirect. Having export default type X; would also help making that more straightforward.

    Reacted by Andrei, whzx5byb, Andre-John Mas, Son Nguyen and Squidgical
  5. AndreiSoroka commented on Sep 9, 2023

    @AndreiSoroka
    Andrei (AndreiSoroka)
    on Sep 9, 2023
    More actions

    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

    Reacted by Yongki Kim, Joseph Earl, Mitchell, Aamnah , taylorhaught, Wolf Yuan, RobertSklv and Rayhan Kinan Muhannad
  6. Jürgen Wißkirchen (wisskirchenj)
    added a commit that references this issue on Oct 15, 2023

    switch Card form interface to type

    636b9f0
  7. movahhedi commented on May 14, 2024

    @movahhedi
    Shahab Movahhedi (movahhedi)
    on May 14, 2024
    More actions

    For those who were looking for "Type annotations for export default", follow #13626.

    Reacted by Jose Vargas
  8. Gouvernathor commented on Jul 19, 2025

    @Gouvernathor
    Gouvernathor
    on Jul 19, 2025
    More actions

    And a workaround is to mark X as a type in the export declaration by using a named export:

    type X = number | string;
    export type {X as default}; // or export {type X as default};

    But that looks fairly indirect. Having export default type X; would also help making that more straightforward.

    In addition, while the following is possible :

    export type Fraction = IFraction;
    export const Fraction = Implementation;

    The following gives an error :

    export type { IFraction as default };
    export default Implementation;

    because it doesn't allow multiple default exports.
    As pointed out earlier, it means that my clients will need to write import { Fraction } from "fractions"; rather than import Fraction from "fractions";, and that the default export is not treated the same as the other exports.

  9. Squidgical commented on Nov 29, 2025

    @Squidgical
    Squidgical
    on Nov 29, 2025
    More actions

    Would very much like to see this. I'm using verbatimModuleSyntax, and while I can default export interfaces just fine, I can't do that for type aliases. It's causing me to use an unpleasant mix of // @ts-* comments and breaking my own conventions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.