TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
keyof operator is a type-level operator in TypeScript that takes an object type and produces a union type of its keys. The resulting type can consist of string, number, and symbol literals, or the broad string, number, and symbol primitive types depending on the target type’s shape. It operates exclusively within the type system during static analysis and has no runtime equivalent.
Behavior with Object Types
When applied to a standard object type or interface,keyof extracts the explicitly defined property keys as a union of string, number, or symbol literals.
Behavior with Index Signatures
If the target type contains an index signature,keyof resolves to the primitive types representing those dictionary keys. Because JavaScript implicitly coerces numeric object keys to strings, a string index signature yields a union of string | number.
The keyof any Idiom
Applying keyof to the any type yields the union of all possible property key types in JavaScript. This resolves to the base primitives allowed as object keys.
Behavior with Union and Intersection Types
Thekeyof operator applies specific algebraic rules when interacting with union (|) and intersection (&) types.
Union Types: keyof produces the intersection of the keys. It only extracts keys that are guaranteed to exist across all constituents of the union type.
keyof produces the union of the keys. It extracts all keys available in the combined type.
Behavior with Primitives and Arrays
When applied to primitive types, arrays, or tuples,keyof extracts the keys of the underlying JavaScript prototype, including methods and indices. Because strings can be indexed numerically (e.g., str[0]), keyof string includes the number primitive type.
Interaction with typeof
Because keyof operates strictly on types, it cannot be applied directly to runtime variables. To extract keys from a runtime value, keyof must be chained with the typeof type query operator, which first resolves the value into a TypeScript type.
Master TypeScript with Deep Grasping Methodology!Learn More





