TypeScript: Cannot 'export default' abstract, ambient class or interface

export default abstract class B {

}

By the way, the same with

export default declare class B {

}

Seems to be a parser bug

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Reactions: 34
  • Comments: 18 (12 by maintainers)

Commits related to this issue

Most upvoted comments

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.

Unsupported export default patterns:

  • export default abstract class C { } Added by #14657
  • export default declare class C { }
  • export default interface I { } Added by #16040
  • export default enum E { }
  • export default const enum E { }
  • export default namespace N { }
  • export default type T = { }

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;

should also cover interfaces (https://github.com/Microsoft/TypeScript/issues/3914):

export default interface User {
    wpUserID: string;
}

I would prefer support for export default enum and export default const enum too. (#3320)

@mhegazy what about export default type foo = {} ?

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

Found this when trying export default enum. Is this really not implemented yet? (6 years)

Does this mean a namespace can be anonymous?

export default namespace {
    export var foo = 100;
}

What about an interface?

export default interface {
    foo: number;
}

Really look forward to #18628! Thanks @NaridaL. 👏👏 👏

@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

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;

I’m OK with leaving it as is if the reasoning is that interfaces, et al, are not vaid EcmaScript and #3917 is implemented.