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

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

Open
zhuravlikjb opened this issue Jul 9, 2015 · 18 comments · Fixed by #16040 · May be fixed by #46120
Open

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

zhuravlikjb opened this issue Jul 9, 2015 · 18 comments · Fixed by #16040 · May be fixed by #46120
Labels
Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@zhuravlikjb
Copy link

export default abstract class B {

}

By the way, the same with

export default declare class B {

}

Seems to be a parser bug

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jul 9, 2015
@DanielRosenwasser
Copy link
Member

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

@mhegazy
Copy link
Contributor

mhegazy commented Jul 9, 2015

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;

@mhegazy mhegazy added Suggestion An idea for TypeScript and removed Bug A bug in TypeScript labels Jul 9, 2015
@danquirk
Copy link
Member

danquirk commented Jul 9, 2015

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.

@DanielRosenwasser
Copy link
Member

Yeah, discussed with @danquirk and @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.

@danquirk danquirk added the In Discussion Not yet reached consensus label Jul 17, 2015
@mhegazy mhegazy changed the title Cannot 'export default' abstract or ambient class Cannot 'export default' abstract, ambient class or interface Feb 22, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Feb 22, 2016

should also cover interfaces (#3914):

export default interface User {
    wpUserID: string;
}

@RyanCavanaugh
Copy link
Member

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

@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this and removed In Discussion Not yet reached consensus labels Mar 15, 2016
@RyanCavanaugh RyanCavanaugh added this to the Community milestone Mar 15, 2016
@RyanCavanaugh
Copy link
Member

Accepting PRs for this.

@DanielRosenwasser
Copy link
Member

Does this mean a namespace can be anonymous?

export default namespace {
    export var foo = 100;
}

What about an interface?

export default interface {
    foo: number;
}

@RyanCavanaugh
Copy link
Member

No other changes except for allowing the export default ... ... modifier combinations that were previously illegal.

@seanchas116
Copy link
Contributor

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

@clavecoder
Copy link

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

@mhegazy mhegazy reopened this May 23, 2017
@mhegazy
Copy link
Contributor

mhegazy commented May 23, 2017

Unsupported export default patterns:

@anstarovoyt
Copy link

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

@simonbuchan
Copy link

simonbuchan commented Jan 11, 2018

@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

@mhegazy
Copy link
Contributor

mhegazy commented Jan 11, 2018

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;

@simonbuchan
Copy link

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>?

NaridaL added a commit to NaridaL/TypeScript that referenced this issue Jan 20, 2018
…icrosoft#3792 (comment).

Added corresponding tests.
NB: export defaults are not yet transformed correctly.
@alvis
Copy link

alvis commented Jan 30, 2018

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

@RyanCavanaugh RyanCavanaugh modified the milestones: Community, Backlog Mar 7, 2019
resolritter added a commit to resolritter/tree-sitter-typescript that referenced this issue Dec 15, 2020
covers
- "[abstract] class"
- interfaces
as per microsoft/TypeScript#3792 (comment) in 2020/12/15

other constructs (microsoft/TypeScript#18628 (comment)) are not yet supported by TypeScript itself
resolritter added a commit to resolritter/tree-sitter-typescript that referenced this issue Dec 15, 2020
covers
- "[abstract] class"
- interfaces
as per microsoft/TypeScript#3792 (comment) in 2020/12/15

other constructs (microsoft/TypeScript#18628 (comment)) are not yet supported by TypeScript itself
resolritter added a commit to resolritter/tree-sitter-typescript that referenced this issue Dec 15, 2020
covers
- "[abstract] class"
- interfaces
as per microsoft/TypeScript#3792 (comment) in 2020/12/15

other constructs (microsoft/TypeScript#18628 (comment)) are not yet supported by TypeScript itself
resolritter added a commit to resolritter/tree-sitter-typescript that referenced this issue Jan 29, 2021
covers
- "[abstract] class"
- interfaces
as per microsoft/TypeScript#3792 (comment) in 2020/12/15

other constructs (microsoft/TypeScript#18628 (comment)) are not yet supported by TypeScript itself
resolritter added a commit to resolritter/tree-sitter-typescript that referenced this issue Mar 2, 2021
covers
- "[abstract] class"
- interfaces
as per microsoft/TypeScript#3792 (comment) in 2020/12/15

other constructs (microsoft/TypeScript#18628 (comment)) are not yet supported by TypeScript itself
@ghost
Copy link

ghost commented Oct 22, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
10 participants