Language-tools: A crazy issue using svelte2dts through svelte2tsx

Created on 23 Mar 2021  路  1Comment  路  Source: sveltejs/language-tools

Describe the bug

I have this component:

<script lang="ts">
  export let one = false;
  export let disabled = false;
  export let two = false;
  export let three = "";
  export let four = false;
  export let fivefive = false;
</script>

<div {disabled}>Hello!</div>

if I use svelte2dts to create it's declaration types it works but I have this error using it:

Argument of type 'string' is not assignable to parameter of type 'never'. ts(2345)

image

If instead I rename this line:

- export let fivefive = false;
+ export let five = false;

it works! It's crazy! I know!

image

I think svelte2dts is using svelte2tsx for conversion, right?

To Reproduce

Component REPO: https://github.com/frederikhors/svslte2tsx-issue-on-never

- clone it
- npm install
- npm run build
- npm link
- cd your svelte ts project
- npm link svslte2tsx-issue-on-never
- use it like below
- open VSCode
- TADA the problem!

Use it like this:

<Test on:click={() => window.location.reload()}>Reload</Test>

Expected behavior

I do not understand with in the first case this is what I got in VSCode for on:

(method) Svelte2TsxComponent<{ one?: boolean; disabled?: boolean; two?: boolean; three?: string; four?: boolean; fivefive?: boolean; }, {}, {}>.$on<never>(event: never, handler: (e: never) => any): () => void

and in the second case I get:

(method) Svelte2TsxComponent<{ one?: boolean; disabled?: boolean; two?: boolean; three?: string; four?: boolean; five?: boolean; }, { [evt: string]: CustomEvent<any>; }, {}>.$on<"click">(event: "click", handler: (e: CustomEvent<any>) => any): () => void

System (please complete the following information):

  • OS: Windows 10
  • IDE: VSCode
  • Plugin/Package: svelte2dts through svelte2tsx
bug

Most helpful comment

Yes, svelte2dts uses svelte2tsx. I have to check why this would make a difference. It should throw a type error in both cases because you don't forward the click event in Test.svelte, on:click will therefore never fire.

>All comments

Yes, svelte2dts uses svelte2tsx. I have to check why this would make a difference. It should throw a type error in both cases because you don't forward the click event in Test.svelte, on:click will therefore never fire.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joelmukuthu picture joelmukuthu  路  14Comments

martonlederer picture martonlederer  路  14Comments

dummdidumm picture dummdidumm  路  24Comments

orta picture orta  路  15Comments

Evertt picture Evertt  路  15Comments