keyof and typeof
keyof and typeof help you build types from values and objects you already have.
That keeps names in sync.
You change one place. Related types follow.
Less copy paste. Fewer typos.
keyof
keyof Type makes a union of the property names.
A union means apple OR orange in one box.
Here the apples are the key names.
typeof on values
In a type position, typeof value captures the type of that value.
This is different from the JavaScript typeof operator in expressions.
Type position means you are writing a type, not running code.
keyof typeof together
A common pattern is keyof typeof on a const object.
You get a union of the object keys.
Great for lookup tables and maps of labels.
Indexed access types
Write Type[Key] to pull the type of one property.
You can combine that with keyof for flexible helpers.
Why this matters
When you rename a field, keyof based types update with it.
Your helpers stay honest.
Honest means they match the real object shape.
Prefer keyof and typeof over hand copying key names. Stay in sync automatically.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.