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
- Can’t have default abstract exports =/ https://github.com/Microsoft/TypeScript/issues/3792 — committed to pablobcb/elm-lead by adelgado 8 years ago
- Can’t have default abstract exports =/ https://github.com/Microsoft/TypeScript/issues/3792 — committed to pablobcb/elm-lead by adelgado 8 years ago
- Changed parser.ts to support all forms of export default described in https://github.com/Microsoft/TypeScript/issues/3792#issuecomment-303526468. Added corresponding tests. NB: export defaults are not... — committed to NaridaL/TypeScript by NaridaL 6 years ago
- support extended import syntax covers - "[abstract] class" - interfaces as per https://github.com/microsoft/TypeScript/issues/3792#issuecomment-303526468 in 2020/12/15 other constructs (https://gith... — committed to resolritter/tree-sitter-typescript by resolritter 4 years ago
- support extended import syntax covers - "[abstract] class" - interfaces as per https://github.com/microsoft/TypeScript/issues/3792#issuecomment-303526468 in 2020/12/15 other constructs (https://gith... — committed to resolritter/tree-sitter-typescript by resolritter 4 years ago
- support extended export syntax covers - "[abstract] class" - interfaces as per https://github.com/microsoft/TypeScript/issues/3792#issuecomment-303526468 in 2020/12/15 other constructs (https://gith... — committed to resolritter/tree-sitter-typescript by resolritter 4 years ago
- support extended export syntax covers - "[abstract] class" - interfaces as per https://github.com/microsoft/TypeScript/issues/3792#issuecomment-303526468 in 2020/12/15 other constructs (https://gith... — committed to resolritter/tree-sitter-typescript by resolritter 4 years ago
- support extended export syntax covers - "[abstract] class" - interfaces as per https://github.com/microsoft/TypeScript/issues/3792#issuecomment-303526468 in 2020/12/15 other constructs (https://gith... — committed to resolritter/tree-sitter-typescript by resolritter 4 years ago
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 defaultpatterns:export default abstract class C { }Added by #14657export default declare class C { }export default interface I { }Added by #16040export 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 defaultsyntax is already long enough, so no modifiers are needed. for a workaround use:should also cover interfaces (https://github.com/Microsoft/TypeScript/issues/3914):
I would prefer support for
export default enumandexport default const enumtoo. (#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?
What about an interface?
Really look forward to #18628! Thanks @NaridaL. 👏👏 👏
@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 numbernot 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
I’m OK with leaving it as is if the reasoning is that interfaces, et al, are not vaid EcmaScript and #3917 is implemented.