【发布时间】:2018-04-29 03:31:12
【问题描述】:
如果我输入以下内容:
interface A {
x: number
}
interface B {
y: number
}
type Z = A | B;
// here it allows me to create a variable of type Z with both members of type A and B.
let z: Z = {
x: 5,
y: 6,
}
我无法确保 Z 类型的对象确实包含 A 的所有成员,但不包含 B 的成员(或相反)。 TypeScript 有可能吗?经过大量研究,我倾向于“否”的答案,但我不确定。
【问题讨论】:
标签: typescript types object-literal