首页 > 解决方案 > 如何在 TypeScript 中创建具有类型别名的对象?

问题描述

new BaseListState<BrandCriteria, Brand>()

这是有效的,我添加

export type BrandListState = BaseListState<BrandCriteria, Brand>;

然后

new BrandListState()

这是不允许的。有什么办法可以解决这个问题?

标签: typescripttypescript-typingstype-alias

解决方案


您正在使用没有构造函数的类型别名(请参阅此处的文档),因此无法使用new. 您需要为此创建类

class BrandListState extends BaseListState<BrandCriteria, Brand> {}

推荐阅读