Repository navigation
Cannot 'export default' abstract, ambient class or interface #3792
Description
Activity
DanielRosenwasser commented
on Jul 9, 2015 MemberMore actionsIn what situations would one need to make an ambient class a default export?
These two are by desing. We have felt that the
export defaultsyntax is already long enough, so no modifiers are needed. for a workaround use:declare class C {} export default C;
Reacted by Josef Kufner, Stefan Burg, xieshuang, Jiri Kapoun, Marquizzo, Nate Abele, jamesamcl, Alvis Tang, Tomáš Hübelbauer, Chris Harrison and 19 more- addedSuggestionAn idea for TypeScriptAn idea for TypeScriptand removedBugA bug in TypeScriptA bug in TypeScript
on 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.
Reacted by Dan Delgado, Dominik Paľo, Andrei Kurosh, Igor Hipólito Vieira, Chad Engler, Santiago Lezica, Koike Michitaro, Aleh Kashnikau, Soichiro Miki, Taro and 67 moreDanielRosenwasser commented
on Jul 9, 2015 MemberMore actionsYeah, discussed with Dan Quirk (@danquirk) and Ryan Cavanaugh (@RyanCavanaugh) offline; in a
.d.tsfile, a default exported ambient class makes sense.I don't think it's that unreasonable to support the original syntax.
- addedIn DiscussionNot yet reached consensusNot yet reached consensus
on Jul 17, 2015 - changed the title
[-]Cannot 'export default' abstract or ambient class[/-][+]Cannot 'export default' abstract, ambient class or interface[/+]on Feb 22, 2016 should also cover interfaces (#3914):
export default interface User { wpUserID: string; }
Reacted by Aluan Haddad, sztanpet, Dmitri K, Jeff Rabovsky, Karlkim Suwanmongkol, Yauheni Prakopchyk, ytkj, Nate Abele, Chris Harrison, Keegan Farley and 8 moreRyanCavanaugh commented
on Mar 7, 2016 MemberMore actionsAnd namespaces:
export default namespace foo { ... }(#7407)Reacted by Bludator, Paweł Szymański, Michal Pochopien and Tomáš Hübelbauer- addedHelp WantedYou can do thisYou can do thisand removedIn DiscussionNot yet reached consensusNot yet reached consensus
on Mar 15, 2016 - added this to the This milestone has been deleted milestone
on Mar 15, 2016 RyanCavanaugh commented
on Mar 15, 2016 MemberMore actionsAccepting PRs for this.
8 remaining items
Unsupported
export defaultpatterns:-
export default abstract class C { }Added by Allow export default abstract class. Related to issue 3792. #14657 -
export default declare class C { } -
export default interface I { }Added by Allow export default interface. Related to issue 3792. #16040 -
export default enum E { } -
export default const enum E { } -
export default namespace N { } -
export default type T = { }
Reacted by Kenneth Brubaker, Dominik Paľo, Doğan Derya, insidewhy, nahakyuu, BobChao87, JongChan Choi (Rieul), Mark Penner, Andrey Starovoyt, Marquizzo and 28 more-
Mohamed Hegazy (@mhegazy) what about
export default type foo = {}?Reacted by Aluan Haddad, Matias Ribichich, Tomáš Hübelbauer, Chris Harrison, inker, Paweł Szymański, Stephen Haney, Telokis, Piotr, Antonio Stoilkov and 1 moreMohamed Hegazy (@mhegazy) for full symmetry with JS export forms, consider (strawman syntax)
export default as ...:JS TS export const x = 123export type T = numberexport { x }export { T }export class Foo {}export interface Foo {}export default class Foo {}export default interface Foo {}export default 123export default as numberReacted by Valentin Trujillonot 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;
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 becauseasalready suggests a type on RHS, but it doesn't really imply the right thing, you're right. Perhapsexport type default <type>?- added a commit that references this issue
on Jan 20, 2018 Really look forward to #18628! Thanks Adrian Leonhard (@NaridaL). 👏👏 👏
Reacted by Chris Harrison- added 3 commits that reference this issue
on Dec 15, 2020 - added a commit that references this issue
on Jan 29, 2021 - added a commit that references this issue
on Mar 2, 2021
By the way, the same with
Seems to be a parser bug