Hi, I'm Jacob. Enjoying devFlipCards? Buy me a coffee

1. What is keyof operator?

keyof operator takes interface or type and returns literal or numerical union of keys, which can be used as a type.

type ExampleType = { name: string, age: number } type KeysOfExampleType = keyof ExampleType // "name" | "age" type TypeWithSameKeysAsExample = { [key in keyof ExampleType]: string } const obj: {value: KeysOfExampleType}: { value: "something" // Type 'something' is not assignable to type 'keyof ExampleType`` } const obj2: TypeWithSameKeysAsExample = {} // Type '{}' is missing the following properties from type 'TypeWithSameKeysAsExample': name, age
Struggling to find common date to meet with your friends? Try our new tool
commondate.xyz