Skip to content

Commit e3422e1

Browse files
authored
docs: Don't recommend TypeScript type assertions for reactive declarations (#8824)
strictly speaking that's not the same and could hide some type errors
1 parent 2a93ca9 commit e3422e1

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

documentation/docs/05-misc/03-typescript.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,14 @@ You cannot type your reactive declarations with TypeScript in the way you type a
176176
</script>
177177
```
178178

179-
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:
179+
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:
180180

181181
```svelte
182182
<script lang="ts">
183183
let count = 0;
184184
185-
$: option1 = (count * 2) as number;
186-
187-
let option2: number;
188-
$: option2 = count * 2;
185+
let doubled: number;
186+
$: doubled = count * 2;
189187
</script>
190188
```
191189

0 commit comments

Comments
 (0)