sveld icon indicating copy to clipboard operation
sveld copied to clipboard

Dies when a function is exported as a prop

Open ghostdevv opened this issue 4 years ago • 2 comments

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');
    }
    ```

ghostdevv avatar Aug 29 '21 19:08 ghostdevv

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.

ghostdevv avatar Aug 29 '21 20:08 ghostdevv

You will need to manually type this.

<script>
  /** @type {() => void} */
  export const x = () => console.log('works')
</script>

metonym avatar Aug 29 '21 20:08 metonym