Closed
Description
Describe the bug
cannot specify param type on arrow functions passed as parameters
e.g.:
<MoreActions {todos} on:checkAll={e => checkAllTodos(e.detail)} />
gives the following ts warning:
Property 'detail' does not exist on type 'Event'.ts(2339)
If I try to specify e to be a CustomEvent like this:
<MoreActions {todos} on:checkAll={e: CustomEvent => checkAllTodos(e.detail)} />
gives the following ts error:
[!] (plugin svelte) ParseError: Expected }
src/components/Todos.svelte
80: <!-- on:checkAll={checkAllHandler} -->
81: <MoreActions {todos}
82: on:checkAll={e: CustomEvent => checkAllTodos(e.detail)}
^
83: on:removeCompleted={removeCompletedTodos}
84: />
ParseError: Expected }
Also tried with
<MoreActions {todos} on:checkAll={(e: CustomEvent) => { checkAllTodos(e.detail)} />
and
<MoreActions {todos} on:checkAll={(e: CustomEvent) => { return checkAllTodos(e.detail)} />
both returning
[!] (plugin svelte) ParseError: Unexpected token
src/components/Todos.svelte
80: <!-- on:checkAll={checkAllHandler} -->
81: <MoreActions {todos}
82: on:checkAll={(e: CustomEvent) => checkAllTodos(e.detail)}
^
83: on:removeCompleted={removeCompletedTodos}
84: />
ParseError: Unexpected token
On the other hand, this works ok:
<script>
const checkAllHandler = (e: CustomEvent) => checkAllTodos(e.detail)
</script>
[...]
<MoreActions {todos} on:checkAll={checkAllHandler}
To Reproduce
create a ts svelte project with:
npx degit orta/template#ts
node scripts/setupTypeScript.js
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
System (please complete the following information):
- OS: Linux xps 5.0.0-1064-oem-osp1 Set the languageId to svelte #69-Ubuntu
- IDE: vscode
- Plugin/Package: [e.g. "Svelte for VSCode", or
svelte-language-server
,svelte-check
, orsvelte2tsx
if you use one of the npm packages directly] (not sure which one)
Additional context
Add any other context about the problem here.