You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot 'export default' abstract, ambient class or interface #3792
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:
declareclassC{}exportdefaultC;
Reacted by Josef Kufner, Stefan Burg, xieshuang, Jiri Kapoun, Marquizzo, Nate Abele, jamesamcl, Alvis Tang, Tomáš Hübelbauer, Chris Harrison and 19 more
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 more
changed the title [-]Cannot 'export default' abstract or ambient class[/-][+]Cannot 'export default' abstract, ambient class or interface[/+]on Feb 22, 2016
Reacted by Aluan Haddad, sztanpet, Dmitri K, Jeff Rabovsky, Karlkim Suwanmongkol, Yauheni Prakopchyk, ytkj, Nate Abele, Chris Harrison, Keegan Farley and 8 more
Reacted by Kenneth Brubaker, Dominik Paľo, Doğan Derya, insidewhy, nahakyuu, BobChao87, JongChan Choi (Rieul), Mark Penner, Andrey Starovoyt, Marquizzo and 28 more
Reacted by Aluan Haddad, Matias Ribichich, Tomáš Hübelbauer, Chris Harrison, inker, Paweł Szymański, Stephen Haney, Telokis, Piotr, Antonio Stoilkov and 1 more
Yeah, sorry, it is a bit ambiguous. Currently, you can sort of export a type as default with:
typeT=number;exportdefaultT;
By analogy of const ~= type:
exportconstx=123;exporttypeT=number;exportdefaultx;exportdefaultT;exportdefault123;exportdefault ???;// can't put type expressions here, only type names, due to ambiguity
The motivating case would would be something like:
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>?
Activity
DanielRosenwasser commentedon Jul 9, 2015
In what situations would one need to make an ambient class a default export?
mhegazy commentedon Jul 9, 2015
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:danquirk commentedon 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 commentedon Jul 9, 2015
Yeah, 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.
[-]Cannot 'export default' abstract or ambient class[/-][+]Cannot 'export default' abstract, ambient class or interface[/+]mhegazy commentedon Feb 22, 2016
should also cover interfaces (#3914):
RyanCavanaugh commentedon Mar 7, 2016
And namespaces:
export default namespace foo { ... }(#7407)RyanCavanaugh commentedon Mar 15, 2016
Accepting PRs for this.
8 remaining items
mhegazy commentedon May 23, 2017
Unsupported
export defaultpatterns:export default abstract class C { }Added by Allow export default abstract class. Related to issue 3792. #14657export default declare class C { }export default interface I { }Added by Allow export default interface. Related to issue 3792. #16040export default enum E { }export default const enum E { }export default namespace N { }export default type T = { }anstarovoyt commentedon Aug 15, 2017
Mohamed Hegazy (@mhegazy) what about
export default type foo = {}?simonbuchan commentedon Jan 11, 2018
Mohamed Hegazy (@mhegazy) for full symmetry with JS export forms, consider (strawman syntax)
export default as ...: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 numbermhegazy commentedon Jan 11, 2018
not sure what that means..
but if it is a .d.ts, we chose not to have a special syntax for this, and the recommendation here is to use
simonbuchan commentedon Jan 11, 2018
Yeah, sorry, it is a bit ambiguous. Currently, you can sort of export a type as default with:
By analogy of
const~=type:The motivating case would would be something like:
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>?Changed parser.ts to support all forms of export default described in m…
alvis commentedon Jan 30, 2018
Really look forward to #18628! Thanks Adrian Leonhard (@NaridaL). 👏👏 👏
support extended import syntax
support extended import syntax
support extended export syntax
support extended export syntax
support extended export syntax