工具泛型

typeof

typeof 的主要用途是在类型上下文中获取变量或者属性的类型

interface Person {
  name: string;
  age: number;
}
const user: Person = { name: "张三", age: 30 };
type User = typeof user; // type User = Person
const hoel: User = { name: "hoel", age: 5 };

in

  • 用来遍历枚举类型:

type Keys = "a" | "b" | "c";

type Obj = {
  [p in Keys]: any;
}; // -> { a: any, b: any, c: any }

keyof

extends

infer

ReturnType

Required

Pick

Omit

Exclude

Extract

Record

  • 此类型包含一组指定的属性且都是必填。

  • 具体的复杂业务场景中,一般会接合 Pick 、Partial 等组合使用,从而过滤和重组出新的类型定义。

Partial

  • 将类型定义的所有属性都修改为可选。

NonNullable

Parameters

ConstructorParameters

readonly

  • 将所有属性定义为自读。

最后更新于

这有帮助吗?