Skip to content

Commit

Permalink
docs: Don't recommend TypeScript type assertions for reactive declara…
Browse files Browse the repository at this point in the history
…tions (#8824)

strictly speaking that's not the same and could hide some type errors
  • Loading branch information
Not-Jayden authored Jun 27, 2023
1 parent 2a93ca9 commit e3422e1
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions documentation/docs/05-misc/03-typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,14 @@ You cannot type your reactive declarations with TypeScript in the way you type a
</script>
```

You cannot add a `: TYPE` because it's invalid syntax in this position. Instead, you can use the `as` or move the definition to a `let` statement just above:
You cannot add a `: TYPE` because it's invalid syntax in this position. Instead, you can move the definition to a `let` statement just above:

```svelte
<script lang="ts">
let count = 0;
$: option1 = (count * 2) as number;
let option2: number;
$: option2 = count * 2;
let doubled: number;
$: doubled = count * 2;
</script>
```

Expand Down

0 comments on commit e3422e1

Please sign in to comment.