DEV Community

Discussion on: Power of conditional types in Typescript

Collapse
 
hamishwhc profile image
HamishWHC

Could you not just have type ErrorType<T extends ApplicationError | Error> = T?

Collapse
 
gauravsoni119 profile image
Gaurav Soni

Yes, we can also use something similar. In our case, T is an object having error property. If you try to use this, you will get an object

(type e = {error: ServerError;})

instead of either ApplicationError or Error. You can try like,

type ErrorType<T extends {error: ApplicationError | Error}> = T['error']