pull/12509/head
Simon Holthausen 2 years ago
parent f5f58460cb
commit d11556c248

@ -556,22 +556,17 @@ let props = $props();
If you're using TypeScript, you can declare the prop types: If you're using TypeScript, you can declare the prop types:
<!-- prettier-ignore -->
```ts ```ts
interface MyProps { type MyProps = any;
required: string; // ---cut---
optional?: number; let { a, b, c, ...everythingElse }: MyProps = $props();
partOfEverythingElse?: boolean;
};
let { required, optional, ...everythingElse }: MyProps = $props();
``` ```
> In an earlier preview, `$props()` took a type argument. This caused bugs, since in a case like this... > In an earlier preview, `$props()` took a type argument. This caused bugs, since in a case like this...
> >
> ```ts > ```ts
> // @errors: 2558 > // @errors: 2558
> let { x = 42 } = $props<{ x?: string }>(); > let { x = 42 } = $props<{ x: string }>();
> ``` > ```
> >
> ...TypeScript [widens the type](https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwBIAHGHIgZwB4AVeAXnilQE8A+ACgEoAueagbgBQgiCAzwA3vAAe9eABYATPAC+c4qQqUp03uQwwsqAOaqOnIfCsB6a-AB6AfiA) of `x` to be `string | number`, instead of erroring. > ...TypeScript [widens the type](https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwBIAHGHIgZwB4AVeAXnilQE8A+ACgEoAueagbgBQgiCAzwA3vAAe9eABYATPAC+c4qQqUp03uQwwsqAOaqOnIfCsB6a-AB6AfiA) of `x` to be `string | number`, instead of erroring.

Loading…
Cancel
Save