Skip to content

Commit c19754c

Browse files
committed
explain why type argument was removed
1 parent 01c67a0 commit c19754c

File tree

1 file changed

+9
-0
lines changed
  • sites/svelte-5-preview/src/routes/docs/content/01-api

1 file changed

+9
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,15 @@ type MyProps = any;
473473
let { a, b, c, ...everythingElse }: MyProps = $props();
474474
```
475475

476+
> In an earlier preview, `$props()` took a type argument. This caused bugs, since in a case like this...
477+
>
478+
> ```ts
479+
> // @errors: 2558
480+
> let { x = 42 } = $props<{ x: string }>();
481+
> ```
482+
>
483+
> ...TypeScript [widens the type](https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwBIAHGHIgZwB4AVeAXnilQE8A+ACgEoAueagbgBQgiCAzwA3vAAe9eABYATPAC+c4qQqUp03uQwwsqAOaqOnIfCsB6a-AB6AfiA) of `x` to be `string | number`, instead of erroring.
484+
476485
Props cannot be mutated, unless the parent component uses `bind:`. During development, attempts to mutate props will result in an error.
477486
478487
### What this replaces

0 commit comments

Comments
 (0)