【问题标题】:How to create object with type alias in TypeScript?如何在 TypeScript 中创建具有类型别名的对象?
【发布时间】:2020-05-05 07:05:09
【问题描述】:
new BaseListState<BrandCriteria, Brand>()

这是有效的,我添加了

export type BrandListState = BaseListState<BrandCriteria, Brand>;

然后

new BrandListState()

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

【问题讨论】:

  • 你只声明了一个类型。要new 它,你也需要一个构造函数。查看 RxJS 代码库中的错误“类”。他们既有类型又有演员:github.com/ReactiveX/rxjs/blob/…

标签: typescript typescript-typings type-alias


【解决方案1】:

您正在使用没有构造函数的类型别名 (see doco here),因此无法使用 new 创建它。您需要为此创建类

class BrandListState extends BaseListState<BrandCriteria, Brand> {}

【讨论】:

    猜你喜欢
    • 2013-09-02
    • 2020-06-24
    • 1970-01-01
    • 1970-01-01
    • 2016-01-25
    相关资源
    最近更新 更多