2021-09-26 ts keyof typeof in的使用

const p_type = {
  name: '1',
  age: 20
};

// typeof
type PersonType = typeof p_type;

const p_type_1: PersonType = {
  name: "1",
  age: 20,
};

// keyof
type keyOfPerson = keyof T;

type nameAndAge2 = keyof PersonType; // "name" | "age"
type nameAndAge1 = keyOfPerson; // "name" | "age"

// in (代表循环遍历)
type keyOfPartial = {
  [K in keyof T]?: T[K]
}

type keyOfRecord = {
  [P in K]?: T;
}

你可能感兴趣的:(2021-09-26 ts keyof typeof in的使用)