Question · JavaScript and TypeScript course · Module 7: Advanced TypeScript
The typeof Operator as a Type Guard
Which operator allows narrowing a primitive type (e.g., string | number) in TypeScript?
Answer options
- typeof - checks the value type and narrows a union type
- instanceof - checks the class type
- as - casts a type to another
- is - defines a custom type guard in a function
You can check the correct answer by solving this task in the CodeWorlds game.