判断一个对象与构造函数是否在一个原型链上
const Person = function () {};
const p1 = new Person();
p1 instanceof Person; // true
var str = "hello world";
str instanceof String; // false
var str1 = new String("hello world");
str1 instanceof String; // true
Record
以 typeof 格式快速创建一个类型,此类型包含一组指定的属性且都是必填。
type Coord = Record<"x" | "y", number>; // 等同于 type Coord = { x: number; y: number; };
描述对象、函数、类,接口中描述的属性都必须包含,但对象有其他一些属性、接口未定义不会报错。
interface LabelledValue { label: string; } function printLabel(labelledObj: LabelledValue) { console.log(labelledObj.label); }