Use the keyof
operator:
type Point = { x: number; y: number };
function print(key: keyof Point) {
// key value can only be 'x' or 'y'
}
References:
Use the keyof
operator:
type Point = { x: number; y: number };
function print(key: keyof Point) {
// key value can only be 'x' or 'y'
}
References: