chunhuigao/study-typescript

TypeScript类型推到应用

Opened this issue · 0 comments

interface IOptions {
  name: string;
  age: number;
  height: number;
  width: number;
}

type TOptionKey = keyof IOptions;

const man: IOptions = {
  name: 'yin',
  age: 20,
  height: 163,
  width: 58,
};

const list: TOptionKey[] = ['name', 'age'];

list.forEach((key: TOptionKey) => {
  console.log(man[key]);
});