Skip to content

svelte-check fails to infer props when component has <svelte:options runes={false} /> #2843

@axel7083

Description

@axel7083

Describe the bug

To test our UI library, we have some backward compatibility tests, where we force a component to be renderer in svelte4, here is an example

<svelte:options runes={false} /> <script lang="ts">  import { Button } from '/@/lib';   export let onclick: () => void;  export let content: string | undefined; </script> <Button on:click={onclick} > {content} </Button>

When using this component inside our test.spec.ts as followed

import '@testing-library/jest-dom/vitest'; import { fireEvent, render } from '@testing-library/svelte'; import { expect, test, vi } from 'vitest'; import ButtonSvelte4Test from './ButtonSvelte4Test.svelte'; test('should render content', () => { const { getByText } = render(ButtonSvelte4Test, { onclick: vi.fn(), content: 'Dummy Button', }); const btn = getByText('Dummy Button'); expect(btn).toBeInTheDocument(); });

We get the following error when running svelte-check

Error: Type 'Mock<Procedure>' is not assignable to type 'never'. const { getByText } = render(ButtonSvelte4Test, { onclick: vi.fn(), content: 'Dummy Button', c:\Users\axels\Documents\github\redhat\podman-desktop\packages\ui\src\lib\button\ButtonSvelte4Test.spec.ts:30:5 Error: Type 'string' is not assignable to type 'never'. onclick: vi.fn(), content: 'Dummy Button', }) 

Removing the <svelte:options runes={false} /> files the error, but not what we want...

Reproduction

See above

Expected behaviour

The props should be properly typed

System Info

  • OS: Windows
  • IDE: Webstorm

Which package is the issue about?

svelte-check

Additional Information, eg. Screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions