Skip to content

Cannot 'export default' abstract, ambient class or interface #3792

Description

export default abstract class B {

}

By the way, the same with

export default declare class B {

}

Seems to be a parser bug

Activity

  1. DanielRosenwasser commented on Jul 9, 2015

    @DanielRosenwasser
    Member

    In what situations would one need to make an ambient class a default export?

  2. mhegazy commented on Jul 9, 2015

    @mhegazy
    Contributor

    These two are by desing. We have felt that the export default syntax is already long enough, so no modifiers are needed. for a workaround use:

    declare class  C {}
    export default C;
  3. danquirk commented on Jul 9, 2015

    @danquirk
    Member

    We should just allow these. It's a strange inconsistency, the workaround is more verbose, and the error gives you no help getting to the workaround.

  4. DanielRosenwasser commented on Jul 9, 2015

    @DanielRosenwasser
    Member

    Yeah, discussed with Dan Quirk (@danquirk) and Ryan Cavanaugh (@RyanCavanaugh) offline; in a .d.ts file, a default exported ambient class makes sense.

    I don't think it's that unreasonable to support the original syntax.

  5. changed the title [-]Cannot 'export default' abstract or ambient class[/-] [+]Cannot 'export default' abstract, ambient class or interface[/+] on Feb 22, 2016
  6. mhegazy commented on Feb 22, 2016

    @mhegazy
    Contributor

    should also cover interfaces (#3914):

    export default interface User {
        wpUserID: string;
    }
  7. RyanCavanaugh commented on Mar 7, 2016

    @RyanCavanaugh
    Member

    And namespaces: export default namespace foo { ... } (#7407)

  8. added this to the milestone on Mar 15, 2016
  9. RyanCavanaugh commented on Mar 15, 2016

    @RyanCavanaugh
    Member

    Accepting PRs for this.

  10. 8 remaining items

  11. mhegazy commented on May 23, 2017

    @mhegazy
    Contributor

    Unsupported export default patterns:

  12. anstarovoyt commented on Aug 15, 2017

    @anstarovoyt

    Mohamed Hegazy (@mhegazy) what about export default type foo = {} ?

  13. simonbuchan commented on Jan 11, 2018

    @simonbuchan

    Mohamed Hegazy (@mhegazy) for full symmetry with JS export forms, consider (strawman syntax) export default as ...:

    JS TS
    export const x = 123 export type T = number
    export { x } export { T }
    export class Foo {} export interface Foo {}
    export default class Foo {} export default interface Foo {}
    export default 123 export default as number
  14. mhegazy commented on Jan 11, 2018

    @mhegazy
    Contributor

    not sure what that means..

    export default as number

    but if it is a .d.ts, we chose not to have a special syntax for this, and the recommendation here is to use

    declare cosnt _t: number;
    export default _t;
  15. simonbuchan commented on Jan 11, 2018

    @simonbuchan

    Yeah, sorry, it is a bit ambiguous. Currently, you can sort of export a type as default with:

    type T = number;
    export default T;

    By analogy of const ~= type:

    export const x = 123;
    export type T = number;
    export default x;
    export default T;
    export default 123;
    export default ???; // can't put type expressions here, only type names, due to ambiguity

    The motivating case would would be something like:

    // Action.ts
    export default as
      | { type: 'login', name: string, password: string }
      | { type: 'logout' }
      | ...

    where currently you would need to bury the export at the bottom of the file.

    I picked export default as <type> as strawman simply because as already suggests a type on RHS, but it doesn't really imply the right thing, you're right. Perhaps export type default <type>?

  16. alvis commented on Jan 30, 2018

    @alvis

    Really look forward to #18628! Thanks Adrian Leonhard (@NaridaL). 👏👏 👏

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

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions