How to create object with type alias in TypeScript?
Asked Answered
I

1

7
new BaseListState<BrandCriteria, Brand>()

This is working and I add

export type BrandListState = BaseListState<BrandCriteria, Brand>;

then

new BrandListState()

This is not allowed. Any way to fix this problem?

Icecap answered 5/5, 2020 at 7:5 Comment(1)
You've only declared a type. To new it, you need to have a constructor, too. Have a look at the error 'classes' in the RxJS codebase. They have both a type and a ctor: github.com/ReactiveX/rxjs/blob/…Kimberlykimberlyn
M
6

You're using a Type Alias (see doco here) which doesn't have constructor, so it can't be created with new. You need to create class for this

class BrandListState extends BaseListState<BrandCriteria, Brand> {}
Multiform answered 5/5, 2020 at 7:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.