Skip to content
CodeWiki
Practice
Paths
Tracks
Cheatsheets
Playground
Glossary
AI era
Search
⌘K
English
English
Chinese
Practice
Paths
Tracks
Cheatsheets
Playground
Glossary
AI era
English
English
Chinese
Practice
/
Quiz
/
TypeScript
/
Type narrowing
A variable is declared as string | number and currently narrowed to string. Why may a lat…
from Type narrowing
TypeScript 6
intermediate
3 min
A variable is declared as string | number and currently narrowed to string. Why may a later assignment of 42 still compile?
Assignments are checked against the declared type, while the observed type can change along control flow.
Narrowing permanently changes the declaration to any.
Every number is implicitly converted to a string.
The assignment is accepted only when strict mode is disabled.
Check
Ask AI about this kata
Report an error
next kata
Why pass a switch default value to assertNever instead of returning "unknown"?
Quiz
A new version is available
Reload