-
-
Notifications
You must be signed in to change notification settings - Fork 212
Closed
Labels
FixedFixed in master branch. Pending production release.Fixed in master branch. Pending production release.bugSomething isn't workingSomething isn't working
Description
Describe the bug
When you have a generics attribute on a script tag (introduced in #2020), it turns off type checking anytime that generic is used as the type of a prop.
Reproduction
Let's say you have a component items.svelte
<script lang="ts" generics="const T extends readonly string[]">
export let items: T
export let currentItem: T[number]
</script>
You can now use this component with any nonsense props. For instance, all of the following pass type checking when none of them should:
<script lang='ts'>
import Items from './items.svelte'
</script>
<!-- here currentItem is invalid -->
<Items items="{['item 1', 'item 2']}" currentItem="foobar" />
<Items items="{['item 1', 'item 2']}" currentItem="{3}" />
<Items items="{['item 1', 'item 2']}" currentItem="{{ foo: 'bar' }}" />
<!-- here items is invalid -->
<Items items="{['item 1', 'item 2', { foo: 'bar' }]}" currentItem="item 1" />
<Items items="{{ foo: 'bar' }}" currentItem="item 1" />
<Items items="foo bar" currentItem="item 1" />
Expected behaviour
None of the above reproduction cases should type check.
However the following case should type check:
<Items items="{['item 1', 'item 2']}" currentItem="item 2" />
Here's the equivalent TypeScript code in the TypeScript playground.
System Info
- OS: macOS
- IDE: VS Code (also reproduced using svelte-check CLI directly)
Relevant packages:
- svelte: 4.0.4
- svelte-check: 3.4.4
- typescript 5.1.6
Which package is the issue about?
svelte-check
Additional Information, eg. Screenshots
No response
gyurielf
Metadata
Metadata
Assignees
Labels
FixedFixed in master branch. Pending production release.Fixed in master branch. Pending production release.bugSomething isn't workingSomething isn't working