In case someone wants to do this for a union of types, instead of just one type, this works perfectly:
type allSubTypesOfUnionType<T> = T extends any ? T[keyof T] : never
So if you have a union of 2 types:
type cheese = {
name: string
holes: number
}
type pizza = {
slices: number
isPepperoni: boolean
}
type yellowFood = cheese | pizza
You can then create a type that extracts all the sub-types as a union:
type possibleTypesOfYellowFood = allSubTypesOfUnionType<yellowFood>
// types is: number | string | boolean
This was adapted from this answer that did the same but for keys instead of sub-types.