Skip to content

TypeScript is not parsed correctly for snippet arguments #2854

@abdel-17

Description

@abdel-17

Describe the bug

There seems to be an issue with parsing object types for snippet parameters. This only happens when the <script> is below the snippet definition.

<!-- everything works when the script tag is at the top... -->
<!-- <script lang="ts"></script> -->

{#snippet foo(props: { props?: Record<string, unknown> })}{/snippet}

<!-- this won't error if you uncomment the snippet above -->
{#snippet bar(props: Record<string, unknown>)}{/snippet}

<!-- ...but not when it's at the bottom -->
<script lang="ts"></script>

EDIT: seems to happen in other cases too, not just snippets.

<CalendarPrimitive.Day
    bind:ref
    class={cn(...)}
    {...restProps}
/>

<script lang="ts">
import {Calendar as CalendarPrimitive} from 'bits-ui'

import {buttonVariants} from '$lib/components/ui/button/index.js'
import {cn} from '$lib/utils.js'

let {ref = $bindable(null), class: className, ...restProps}: CalendarPrimitive.DayProps = $props()
</script>

Reproduction

https://github.com/abdel-17/snippet-ts-bug

Expected behaviour

It should not error

System Info

  • OS: [e.g. Linux]
  • IDE: [e.g. Neovim]

Which package is the issue about?

No response

Additional Information, eg. Screenshots

Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglimitationConstraints of the existing architecture make this hard to fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions