Complete the code to declare a variable with the same type as another variable using typeof.
let name = "Alice"; let userName: [1] = "Bob";
In TypeScript, typeof used in a type context extracts the type of a variable. So typeof name means the type of the variable name.
Complete the code to declare a function parameter type using typeof operator on a variable.
const age = 30; function printAge(value: [1]) { console.log(value); }
Using typeof age in the parameter type means the parameter must be the same type as age, which is number.
Fix the error by completing the type alias using typeof operator on a variable.
const isActive = true;
type ActiveStatus = [1];The correct way to create a type alias from a variable's type is to use typeof isActive. This extracts the type boolean from the variable.
Fill both blanks to create a type alias for the type of a variable and use it in a function parameter.
const score = 100; type ScoreType = [1]; function printScore(value: [2]) { console.log(value); }
First, ScoreType is defined as typeof score to get the type of score. Then the function parameter uses ScoreType as its type.
Fill all three blanks to declare a variable, create a type alias using typeof, and use it in a function parameter.
const isEnabled = false; type EnabledType = [1]; let flag: [2] = false; function toggle(value: [3]) { console.log(value); }
We first create a type alias EnabledType using typeof isEnabled. Then we declare flag with type EnabledType. Finally, the function parameter uses EnabledType as its type.