1
Fork 0

Tight -> narrow

This commit is contained in:
prescientmoon 2025-06-19 13:36:45 +02:00
parent 1aa6356e14
commit c97acefaa6
Signed by: prescientmoon
SSH key fingerprint: SHA256:WFp/cO76nbarETAoQcQXuV+0h7XJsEsOCI0UsyPIy6U

View file

@ -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]