DEV Community


Discussion on: Power of conditional types in Typescript

gauravsoni119 profile image
Gaurav Soni Author

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']