Skip to content

Latest commit

 

History

History
20 lines (15 loc) · 715 Bytes

Type template literals, utility types, and operators.md

File metadata and controls

20 lines (15 loc) · 715 Bytes

To pull it all together, I'll sometimes use a technique like this to make my life easier.

type User = {
  firstName: string;
  lastName: string;
  age: number;
};

type ActionTypes = `update-${keyof User}`;

type Actions<T, K extends keyof T & string> = {
  type: `update-${K}`;
  payload: T[K];
};

type UpdateNameAction = Actions<User, 'firstName'>;

You can see it in action here.