Q:

Extract the type of a property in an union type

I use the code below:
interface A {
  color: "red"
  a: string
}
interface B {
  color: "green"
  b: number
}
interface C {
  color: "blue"
  c: boolean
}

type D = A | B | C // Type is like: { color: "red" | "green" | "blue" }

declare const fakeVariable: D

type Color = typeof fakeVariable.color // Type is: "red" | "green" | "blue"

It works as expected. But, is it possible to automatically create the type Color without to declare a fake variable?

A:

You just need to use a index type query: 
type Color = D['color']

