sveld
sveld copied to clipboard
Dies when a function is exported as a prop
In the example svelte file Test.svelte with the contents:
<script>
export const x = () => console.log('works')
</script>
it generates
/// <reference types="svelte" />
import { SvelteComponentTyped } from "svelte";
export interface TestProps {
}
export default class Test extends SvelteComponentTyped<
TestProps,
{},
{}
> {
x: () => console.log('works');
}
```
This is the console output:
> rollup -c
src/index.js → ./dist/index.mjs, ./dist/index.js...
created ./dist/index.mjs, ./dist/index.js in 329ms
SyntaxError: ';' expected. (19:25)
17 |
18 |
> 19 | x: () => console.log('works');
| ^
20 | }
SyntaxError: ';' expected. (19:25)
17 |
18 |
> 19 | x: () => console.log('works');
| ^
20 | }
created TypeScript definitions.
created TypeScript definitions.
You will need to manually type this.
<script>
/** @type {() => void} */
export const x = () => console.log('works')
</script>