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
When using SWC with a Next.js project (v15), an abstract method in a TypeScript class causes a compilation error when visiting the page in the browser. The error message is:
Error: ×Expected '{', got 'abstract'
This issue occurs even though the code is valid TypeScript and compiles without issues using tsc. Renaming the method to something else (e.g., accessor_foo) resolves the issue, even though the original name is valid TypeScript.
Steps to Reproduce
Create a TypeScript abstract class with an abstract accessor method::
kdy1
changed the title
SWC Fails to Transpile Abstract Method in TypeScript Abstract Class
SWC Fails to Transpile Abstract Method named accessorJan 6, 2025
Describe the bug
When using SWC with a Next.js project (v15), an abstract method in a TypeScript class causes a compilation error when visiting the page in the browser. The error message is:
This issue occurs even though the code is valid TypeScript and compiles without issues using
tsc
. Renaming the method to something else (e.g.,accessor_foo
) resolves the issue, even though the original name is valid TypeScript.Steps to Reproduce
abstract accessor
method::npm run dev
and visit the relevant page.Debugging Steps Taken
Environment
Minimal Reproducible Example
Workaround
Renaming
accessor
to another name likeaccessor_foo
or replacing with a concrete implementation resolves the issue but both are not ideal.Input code
No response
Config
The issue persists even after ensuring the tsconfig.json is correctly configured:
Playground link (or link to the minimal reproduction)
https://play.swc.rs/?version=1.10.4&code=H4sIAAAAAAAAA22QzWrDMBCE73qKxScb8gOlJ9sN5NhbDyb3jXadiAYpSOskEPzulSw3bUNv0s4w8%2B3y7ey8AO6DeNQC%2BoQhwHb%2Bdhyk7RawgzcY7Kd1V7uBu4Ifv6Ea4tPYQ%2FN7fGQk9v9KqDWH4HxJKFhDV9Wwa1R0nKNV3qmspgYAzzJ4C3I0YWUoZYxqVCoTJjLgm7ClJ9xcuZirM66huEAhUV4aWvbOFSkuQyZlj36aPLHliOr78ZereH0pHlCcz0jc43AS6AerxTg7YX7ggeeltLMRO3HEVsvXSS%2BrFDOntmQum3tyrB73GNt1mjax6AsLoiWirwEAAA%3D%3D&config=H4sIAAAAAAAAA1WPSw7CMAxE9z1F5DUL1AUL7sAhouBWQfkpdiWqqncnf2AXv5nJ2MckBLxIwV0c6ZmGICNhHHMitDuW70SA94Ckog4Ml64yZYnjhoWcVQCWcUXOIaT5Os8tAMZ7woQXaQgbs9rpZf%2BtVN6GiET%2FxmyVbjUjXxun1grWP7citlPyunWDG3xNvWx8DJoePVnuOD9fu6hdFgEAAA%3D%3D
SWC Info output
No response
Expected Behavior
The page should load without errors, as the code is valid TypeScript.
Actual Behavior
The page fails to load, and the following error is shown:
Renaming
abstract accessor(data: T): V;
toabstract accessor_foo(data: T): V; resolves
the issue.Version
1.10.4
Additional context
No response
The text was updated successfully, but these errors were encountered: