const num = 42; type NumType = typeof num; console.log(typeof num);
The typeof operator in JavaScript returns a string describing the type of the value at runtime. Here, num is a number, so typeof num returns "number".
In TypeScript, typeof used in a type context (like type NumType = typeof num;) extracts the type of the variable, but this does not affect the runtime output.
user2?const user = { name: "Alice", age: 30 }; type UserType = typeof user; const user2: UserType = { name: "Bob", age: 25 };
The typeof operator in a type context extracts the type of the variable user, which is an object with name as string and age as number.
So UserType is the type describing that object shape, and user2 must match it.
const value = 10; type ValueType = typeof value; const newValue: ValueType = "10";
value and what is assigned to newValue.The type ValueType is number because value is a number.
Assigning a string "10" to newValue causes a type error: string is not assignable to number.
typeof in a type context to declare a variable with the same type as config?const config = { url: "https://example.com", timeout: 5000 };
Option A correctly uses typeof config without parentheses or brackets to get the type of config.
Options B, C, and D use invalid syntax: parentheses, function call, or array brackets are not valid here.
settingsCopy after the assignment?const settings = { darkMode: true, version: 1 }; type SettingsType = typeof settings; function cloneSettings(s: SettingsType): SettingsType { return { ...s }; } const settingsCopy = cloneSettings(settings);
The SettingsType is the type of settings, which is an object with darkMode as boolean and version as number.
The function cloneSettings returns a new object with the same type.
Therefore, settingsCopy has the same type as settings.