Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svelte 5: Cannot specify this' type in TypeScript #11731

Closed
Florob opened this issue May 22, 2024 · 3 comments · Fixed by #11795
Closed

Svelte 5: Cannot specify this' type in TypeScript #11731

Florob opened this issue May 22, 2024 · 3 comments · Fixed by #11795

Comments

@Florob
Copy link

Florob commented May 22, 2024

Describe the bug

When using TypeScript the syntax for specifying the type of this is no longer supported. Builds throw a syntax error. Dev server removes the type, but keeps the this parameter, leading to syntax errors at runtime.

Reproduction

function onclick(this: HTMLButtonElement, event: Event) 

REPL

Logs

vite build:
✓ 204 modules transformed.
x Build failed in 3.56s
error during build:
RollupError: Expected ident
    at getRollupError (file://.../node_modules/rollup/dist/es/shared/parseAst.js:396:41)
    at ParseError.initialise (file://.../node_modules/rollup/dist/es/shared/node-entry.js:11332:28)
    at convertNode (file://.../node_modules/rollup/dist/es/shared/node-entry.js:13082:10)
    at convertProgram (file://.../node_modules/rollup/dist/es/shared/node-entry.js:12399:12)
    at Module.setSource (file://.../node_modules/rollup/dist/es/shared/node-entry.js:14246:24)
    at async ModuleLoader.addModuleSource (file://.../node_modules/rollup/dist/es/shared/node-entry.js:18892:13)

Browser via vite:
Uncaught SyntaxError: missing formal parameter

System Info

System:
    OS: Linux 6.9 Arch Linux
    CPU: (8) x64 Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz
    Memory: 9.32 GB / 15.20 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.2.0 - /usr/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 10.8.0 - /usr/bin/npm
  Browsers:
    Chromium: 125.0.6422.60
  npmPackages:
    svelte: ^5.0.0-next.138 => 5.0.0-next.138 
    webpack: ^5.64.1 => 5.91.0

Severity

blocking an upgrade

@dummdidumm dummdidumm added this to the 5.0 milestone May 22, 2024
@dummdidumm
Copy link
Member

related to #11502, though I wonder if we should treat this instance specifically

@paoloricciuti
Copy link
Member

related to #11502, though I wonder if we should treat this instance specifically

Well this is more of a typing issue rather than a runtime one right? I would say if we can we should try to make this work.

@Rich-Harris
Copy link
Member

yeah, we should definitely fix this

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

Successfully merging a pull request may close this issue.

4 participants