-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Snippet doesn't satisfy the Snippet type, apparently #13759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Maybe related to language tools |
This problem seems to affect components that receive optional snippets (perhaps the "optional" part is not required for reproduction): <script lang="ts">
import Other from './Other.svelte'; // This one contains the label snippet in its Props too.
type Props = {
label?: Snippet;
};
let props = {
label,
}: Props = $props();
let noLabel = $derived(<some logic>);
</script>
<Other label={noLabel ? undefined : label} /> Here, I cannot use |
For me it's caused by the snippet prop's name clashing with Here's my example: // DraggableWindow.svelte
<script lang="ts">
import type { Snippet } from 'svelte';
import type { HTMLAttributes } from 'svelte/elements';
type Props = HTMLAtttributes<HTMLDivElement> & {
/** Title of the window */
title?: Snippet;
}
// ...
</script> // SettingsWindow.svelte
<script lang="ts>
import DraggableWindow from '../DraggableWindow.svelte';
</script>
{#snippet title()}
<h2>Settings</h2>
{/snippet}
// ❌ Type '() => ReturnType<import("svelte").Snippet>' is not assignable to type 'string & Snippet<[]>'.
<DraggableWindow {title}>...</DraggableWindow> This is because title?: string | undefined | null; So the solution is to omit - type Props = HTMLAtttributes<HTMLDivElement> & {
+ type Props = Omit<HTMLAtttributes<HTMLDivElement>, "title"> & {
/** Title of the window */
title?: Snippet;
} |
Hello. I did not need anything else but what's in here to reproduce, but that was 3 months ago, and many updates to tooling have been rolled out. I'll verify if the validity of this claim remains current as soon as I finish breakfast. |
@paoloricciuti I am currently unable to reproduce my sample myself, even with the back-then dependency versions. I think this may have been a tooling issue that is no longer present. I will double-check with the project at work (a component library for Bootstrap); the repro I have in my personal PC is no longer exhibiting the problem. It appears that my only problem with the Snippet type ATM is: sveltejs/language-tools#2653 |
This one also doesn't reproduce anymore. |
Describe the bug
In a class, I have the following overload:
This is a SvelteKit project that produces an NPM library package. When the project is built, the
dist
folder contains:Great so far. Now the class is imported in a Vite + Svelte project by importing it from the built NPM package. The importer declares the following snippet:
Then, this snippet is used in a call to
show()
:TypeScript is now unhappy. The word "overlay" has the squiggly red line and the error says:
So the snippet
overlay
is typed as a function whose return type is the return type of theSnippet
type fromsvelte
, instead of just being a snippet.Reproduction
Hopefully the above information is enough to reproduce? Do let me know, though.
Logs
No response
System Info
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: