Tight -> narrow
This commit is contained in:
parent
1aa6356e14
commit
c97acefaa6
1 changed files with 1 additions and 1 deletions
|
@ -69,7 +69,7 @@ const nums: number[] = [0]
|
|||
nums.push("oops") // type error!
|
||||
```
|
||||
|
||||
The issue is that (informally), at every point, TypeScript keeps track of the tightest type possible for the variables involved. That is, `nums` has type `number[]`, hence the type mismatch. Still, we can guide TypeScript into widening said "tightest type" with a type annotation, thus recreating the bug without any new functions:
|
||||
The issue is that (informally), at every point, TypeScript keeps track of the most narrow type possible for the variables involved. That is, `nums` has type `number[]`, hence the type mismatch. Still, we can guide TypeScript into widening said "most narrow type" with a type annotation, thus recreating the bug without any new functions:
|
||||
|
||||
```ts
|
||||
const nums: number[] = [0]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue