Conditional Type

Is it possible to have a type which resolves between two types with a conditional whether a field on an object exists or not.

Type A = {a: string, b: string}
Type B = {c: string, b: number}

Type C = A | B

I want to achieve something like this
const obj: C;
obj.a ? obj.b : obj.b + 1

I know the example can be resolved with another way but my use case is more complex. I just want the type to be resolved like that. How do you go about this?
Was this page helpful?