# Keyof 类型操作符

keyof 操作符接受一个对象类型,并生成其键的字符串或数字字面值联合:

# 通用

interface account {
    name: string;
    password: string;
}

type login = keyof account;
// type login = 'name' | 'password';

# 索引

数字索引

type Arrayish = { [n: number]: unknown };
type A = keyof Arrayish;
// type A = number;

字符串索引

type Mapish = { [k: string]: boolean };
type M = keyof Mapish;
// type M = string | number;