Typescript spread `interface` keys as union of strings

Viewed 3872

Is it possible to typecheck a function argument to be one of the interface's keys:

export interface IUser {
  id: string;
  email: string;
  password: string;
}

const updateUserProperty = (property: 'id' | 'email' | 'password') => e =>
  this.setState({ [property]: e.target.value });

I'd like 'id' | 'email' | 'password' not be hardcoded.

In a JS way eg. IUser being an object, I can translate that to Object.keys(IUser).join(' | ')

1 Answers
Related