# Previously

如果指定的属性在指定的对象或其原型链中,则 in 运算符返回 true

const car = { make: 'Honda', model: 'Accord', year: 1998 };

console.log('make' in car);
// expected output: true

delete car.make;
if ('make' in car === false) {
  car.make = 'Suzuki';
}

console.log(car.make);
// expected output: "Suzuki"

1
2
3
4
5
6
7
8
9
10
11
12
13

# 定义 Typescript in 关键字

in

用来遍历枚举类型。

# 使用

type Keys = 'name' | 'age';

interface Profile {
  [P in Keys]: string;
}

/**
 * interface Profile {
 *    name: string;
 *    age: string;
 * }
 *
 */

1
2
3
4
5
6
7
8
9
10
11
12
13
14

# 快来耍耍啊

# 🌰🌰

// template
1

# 游乐场


# 参考答案

// answer
1

# 参考资料