Skip to content

Commit 01c67a0

Browse files
committed
breaking: make $props() rune non-generic
1 parent d577740 commit 01c67a0

File tree

8 files changed

+20
-15
lines changed

8 files changed

+20
-15
lines changed

.changeset/fair-spies-repeat.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+
breaking: make `$props()` rune non-generic

packages/svelte/elements.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export type ToggleEventHandler<T extends EventTarget> = EventHandler<ToggleEvent
6767

6868
export interface DOMAttributes<T extends EventTarget> {
6969
// Implicit children prop every element has
70-
// Add this here so that libraries doing `$props<HTMLButtonAttributes>()` don't need a separate interface
70+
// Add this here so that libraries doing `let { ...props }: HTMLButtonAttributes = $props()` don't need a separate interface
7171
children?: import('svelte').Snippet;
7272

7373
// Clipboard Events

packages/svelte/src/main/ambient.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ declare namespace $effect {
172172
* Declares the props that a component accepts. Example:
173173
*
174174
* ```ts
175-
* let { optionalProp = 42, requiredProp } = $props<{ optionalProp?: number; requiredProps: string}>();
175+
* let { optionalProp = 42, requiredProp }: { optionalProp?: number; requiredProps: string } = $props();
176176
* ```
177177
*
178178
* https://svelte-5-preview.vercel.app/docs/runes#$props
179179
*/
180-
declare function $props<T>(): T;
180+
declare function $props(): any;
181181

182182
/**
183183
* Inspects one or more values whenever they, or the properties they contain, change. Example:

packages/svelte/src/main/public.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ declare const SnippetReturn: unique symbol;
186186
/**
187187
* The type of a `#snippet` block. You can use it to (for example) express that your component expects a snippet of a certain type:
188188
* ```ts
189-
* let { banner } = $props<{ banner: Snippet<{ text: string }> }>();
189+
* let { banner }: { banner: Snippet<{ text: string }> } = $props();
190190
* ```
191191
* You can only call a snippet through the `{@render ...}` tag.
192192
*/

packages/svelte/types/index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ declare module 'svelte' {
187187
/**
188188
* The type of a `#snippet` block. You can use it to (for example) express that your component expects a snippet of a certain type:
189189
* ```ts
190-
* let { banner } = $props<{ banner: Snippet<{ text: string }> }>();
190+
* let { banner }: { banner: Snippet<{ text: string }> } = $props();
191191
* ```
192192
* You can only call a snippet through the `{@render ...}` tag.
193193
*/
@@ -1879,7 +1879,7 @@ declare module 'svelte/legacy' {
18791879
/**
18801880
* The type of a `#snippet` block. You can use it to (for example) express that your component expects a snippet of a certain type:
18811881
* ```ts
1882-
* let { banner } = $props<{ banner: Snippet<{ text: string }> }>();
1882+
* let { banner }: { banner: Snippet<{ text: string }> } = $props();
18831883
* ```
18841884
* You can only call a snippet through the `{@render ...}` tag.
18851885
*/
@@ -2615,12 +2615,12 @@ declare namespace $effect {
26152615
* Declares the props that a component accepts. Example:
26162616
*
26172617
* ```ts
2618-
* let { optionalProp = 42, requiredProp } = $props<{ optionalProp?: number; requiredProps: string}>();
2618+
* let { optionalProp = 42, requiredProp }: { optionalProp?: number; requiredProps: string } = $props();
26192619
* ```
26202620
*
26212621
* https://svelte-5-preview.vercel.app/docs/runes#$props
26222622
*/
2623-
declare function $props<T>(): T;
2623+
declare function $props(): any;
26242624

26252625
/**
26262626
* Inspects one or more values whenever they, or the properties they contain, change. Example:

sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,12 @@ To get all properties, use rest syntax:
465465
let { a, b, c, ...everythingElse } = $props();
466466
```
467467

468-
If you're using TypeScript, you can use type arguments:
468+
If you're using TypeScript, you can declare the prop types:
469469

470470
```ts
471471
type MyProps = any;
472472
// ---cut---
473-
let { a, b, c, ...everythingElse } = $props<MyProps>();
473+
let { a, b, c, ...everythingElse }: MyProps = $props();
474474
```
475475

476476
Props cannot be mutated, unless the parent component uses `bind:`. During development, attempts to mutate props will result in an error.

sites/svelte-5-preview/src/routes/docs/content/01-api/03-snippets.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,11 @@ Snippets implement the `Snippet` interface imported from `'svelte'`:
229229
+<script lang="ts">
230230
+ import type { Snippet } from 'svelte';
231231
+
232-
+ let { data, children, row } = $props<{
232+
+ let { data, children, row }: {
233233
+ data: any[];
234234
+ children: Snippet;
235235
+ row: Snippet<[any]>;
236-
+ }>();
236+
+ } = $props();
237237
</script>
238238
```
239239

@@ -246,13 +246,13 @@ We can tighten things up further by declaring a generic, so that `data` and `row
246246
+<script lang="ts" generics="T">
247247
import type { Snippet } from 'svelte';
248248

249-
let { data, children, row } = $props<{
249+
let { data, children, row }: {
250250
- data: any[];
251251
+ data: T[];
252252
children: Snippet;
253253
- row: Snippet<[any]>;
254254
+ row: Snippet<[T]>;
255-
}>();
255+
} = $props();
256256
</script>
257257
```
258258

sites/svelte-5-preview/src/routes/docs/render.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ const render_content = (filename, body) =>
166166
twoslashBanner: (filename, source) => {
167167
const injected = [
168168
`// @filename: runes.d.ts`,
169-
`declare function $props<T>(): T`,
169+
`declare function $props(): any`,
170170
`declare function $state<T>(initial: T): T`,
171171
`declare function $derived<T>(value: T): T`,
172172
`declare const $effect: ((callback: () => void | (() => void)) => void) & { pre: (callback: () => void | (() => void)) => void };`

0 commit comments

Comments
 (0)