1. 首页
  2. JS

Ts中 type 和 interface 定义类型区别

type 和 interface 类型定义区别,定义类型字段时,均使用英文分号换行

1.定义联合类型使用 type ,比如:

export type SelectValue = RawValue | undefined;

2.定义函数使用 type

export type HandleGeneratorFn = (config: {
    tooltipPrefixCls?: string;
    prefixCls?: string;
    info: HandleGeneratorInfo;
}) => React.ReactElement;

3.定义泛型实例使用 type

export type SliderClassNames = Partial<Record<SemanticName, string>>;

4.其它均使用 interface 来定义类型

5.前端类型定义名称示例

User

UserCopy

UserContactInfo


TOP