Skip to content

Compiler accepts abstract declare class as well as declare abstract class #65356

Closed

Description

@magic-akari

🔎 Search Terms

abstract declare class, declare abstract class, ambient class declaration, modifier order

🕗 Version & Regression Information

Reproduced with TypeScript 6.0.3 and 7.0.2 using tsc --noEmit --strict --target esnext repro.ts. Both versions behave the same way.

⏯ Playground Link

https://www.typescriptlang.org/play/?target=99&ts=6.0.3#code/CYUwxgNghgTiAEUBGBnALjKY30lFK8AgvAN4C+AUMuptvKHnLtAfAEJlVA

💻 Code

declare abstract class A {}
abstract declare class B {}

🙁 Actual behavior

Both declarations compile without diagnostics. The TypeScript conformance suite exercises declare abstract class. We couldn’t find a corresponding test or design note for abstract declare class. Conformance test

🙂 Expected behavior

We’d like to confirm whether placing abstract before declare is intentional. If both orders are supported, we can accept both in swc-next. If only declare abstract is intended, a diagnostic for the reverse order would be helpful. That clarification would settle the parser question in swc-project/swc-next-issues#149.

Additional information about the issue

On November 6, 2026, GitHub Code Search returned 73,344 files for "declare abstract class" language:TypeScript and 18 for "abstract declare class" language:TypeScript. We inspected all 18 reverse-order hits. After deduplicating identical files, 12 remained. Nine were test or example files containing declarations, two contained the text in test strings, and one was an invalid example with a repeated modifier. These counts cover indexed files matching the exact phrases. Example from OpenHarmony’s parser tests

Activity

  1. RyanCavanaugh commented on Nov 6, 2026

    @RyanCavanaugh
    Member

    Normally we enforce an ordering whenever multiple erased keywords appear consecutively, but this was an oversight (abstract is a CodePlex-era feature so I don't have notes at hand). Seems like we got very lucky in this case and can safely ban the "wrong" order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions