Skip to content

Commit 919acad

Browse files
authored
fix: bump dts-buddy for better exports type generation (#12262)
#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.
1 parent 84325bf commit 919acad

File tree

5 files changed

+176
-175
lines changed

5 files changed

+176
-175
lines changed

.changeset/friendly-clouds-rhyme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: bump dts-buddy for better type generation

packages/svelte/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
"@rollup/plugin-terser": "^0.4.4",
123123
"@rollup/plugin-virtual": "^3.0.2",
124124
"@types/aria-query": "^5.0.4",
125-
"dts-buddy": "^0.5.0",
125+
"dts-buddy": "^0.5.1",
126126
"esbuild": "^0.19.11",
127127
"rollup": "^4.9.5",
128128
"source-map": "^0.7.4",

packages/svelte/src/index.d.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ export type ComponentType<Comp extends SvelteComponent = SvelteComponent> = (new
256256

257257
declare const SnippetReturn: unique symbol;
258258

259+
// Use an interface instead of a type, makes for better intellisense info because the type is named in more situations.
259260
/**
260261
* The type of a `#snippet` block. You can use it to (for example) express that your component expects a snippet of a certain type:
261262
* ```ts
@@ -267,20 +268,17 @@ declare const SnippetReturn: unique symbol;
267268
*
268269
* @template Parameters the parameters that the snippet expects (if any) as a tuple.
269270
*/
270-
export type Snippet<Parameters extends unknown[] = []> =
271-
// this conditional allows tuples but not arrays. Arrays would indicate a
272-
// rest parameter type, which is not supported. If rest parameters are added
273-
// in the future, the condition can be removed.
274-
number extends Parameters['length']
275-
? never
276-
: {
277-
(
278-
this: void,
279-
...args: Parameters
280-
): typeof SnippetReturn & {
281-
_: 'functions passed to {@render ...} tags must use the `Snippet` type imported from "svelte"';
282-
};
283-
};
271+
export interface Snippet<Parameters extends unknown[] = []> {
272+
(
273+
this: void,
274+
// this conditional allows tuples but not arrays. Arrays would indicate a
275+
// rest parameter type, which is not supported. If rest parameters are added
276+
// in the future, the condition can be removed.
277+
...args: number extends Parameters['length'] ? never : Parameters
278+
): typeof SnippetReturn & {
279+
_: 'functions passed to {@render ...} tags must use the `Snippet` type imported from "svelte"';
280+
};
281+
}
284282

285283
interface DispatchOptions {
286284
cancelable?: boolean;

0 commit comments

Comments
 (0)