Skip to content

svelte-check: Doesn't flag TS2614 about exporting snippets from .svelte files, but TypeScript does #3083

Description

@webJose

Describe the bug

Given a .svelte file that exports snippets:

<script lang="ts" module>
    import Children1Col from "$lib/tests/Children1Col.svelte";
    import ChildrenEmptyCell from "$lib/tests/ChildrenEmptyCell.svelte";

    export { children1Col, childrenEmptyCell };
</script>

{#snippet children1Col()}
    <Children1Col />
{/snippet}

{#snippet childrenEmptyCell()}
    <ChildrenEmptyCell />
{/snippet}

And later importing one of them:

import { children1Col } from '$lib/tests/TestSnippets.svelte';

Makes TypeScript flag the statement with TS2614:

Image

That's fine, I guess. I believe this happens because of the ambient module for *.svelte. We cannot predict that a particular .svelte file will export something out of the module script. So I proceed to use // @ts-expect-error. That makes the error goes away.

However, svelte-check says:

Error: Unused '@ts-expect-error' directive. 
import Layout from '$lib/tests/Layout.svelte';
// @ts-expect-error TS2614
import { children1Col } from '$lib/tests/TestSnippets.svelte';

So I can make TypeScript happy, or svelte-check happy. I cannot make both happy.

Reproduction

See previous section.

Expected behaviour

svelte-check and TypeScript should be in accordance with each other.

System Info

  • OS: Windows
  • IDE: VS Code
  • Svelte for VS Code version: 110.3.0

Which package is the issue about?

svelte-check

Additional Information, eg. Screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions