-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Using a generic type as an argument to a Snippet breaks types generation of a component #12202
Comments
I suspect this has something to do with |
I found other cases where types are not generated anymore. There also seems to be an issue using ComponentProps for components that have a Snippet on their props. For example the following causes the outer component to not generate types anymore. Outer.svelte <script lang="ts">
import type { ComponentProps } from 'svelte';
import Inner from './Inner.svelte';
let { foo }: ComponentProps<Inner> = $props();
</script> Inner.svelte <script lang="ts">
import { type Snippet } from 'svelte';
let {
foo,
footer
}: {
foo: string;
footer?: Snippet;
} = $props();
</script> |
Investigating this. For some reason TypeScript seems to want to unpack the types when using the |
Investigated this further. Ultimately this is a TypeScript limitation: For reasons that I don't understand TypeScript is not able to correctly backtrack imports if the declaration file is written of the form declare module "svelte" {
class Foo {}
export { Foo }
} TypeScript will then error with something like declare module "svelte" {
export class Foo {}
export {}
} The error does not appear. It seems that the extra indirection is too much for TypeScript to know where to find the import and then errors. The fix is to revert Rich-Harris/dts-buddy#82 in dts-buddy and instead add |
sveltejs/svelte#12202 revealed that TypeScript has a harder time tracing imports when they are indirectly exposed, e.g. `function foo(): void; ... export { foo }` instead of `export function foo(): void;`, which can lead to bugs down the line. Ultimately this is a TypeScript limitation but in the meantime adding a lone `export {}` along `export function/const/etc` statements has the same effect as #82
* Revert "Fix exports (#82)" This reverts commit b9435de. * fix: better way of preventing unintended exports sveltejs/svelte#12202 revealed that TypeScript has a harder time tracing imports when they are indirectly exposed, e.g. `function foo(): void; ... export { foo }` instead of `export function foo(): void;`, which can lead to bugs down the line. Ultimately this is a TypeScript limitation but in the meantime adding a lone `export {}` along `export function/const/etc` statements has the same effect as #82 * fix tests
#12202 revealed that TypeScript has a harder time tracing imports when they are indirectly exposed, e.g. `function foo(): void; ... export { foo }` instead of `export function foo(): void;`, which can lead to bugs down the line (such as in that issue). A new `dts-buddy` version fixes this, which in turn fixes #12202 This also adjustes the `Snippet` type and turns it into an interface, which makes for better intellisense: The type will be unpacked in less situations, resulting a more readable and named type.
Describe the bug
When I use a generic type as an argument to a snippet, svelte-package does not properly generate a Component.d.ts file for my component anymore.
While I understand the following test case is a bit weird, I do have several components where I use the type of one of the properties to determine the type that is passed to subsequent snippets.
Reproduction
Logs
No response
System Info
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: