我使用以下代码:
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"
它按预期工作。但是,是否可以自动创建类型Color
而无需声明假变量?