【发布时间】:2020-01-03 00:50:11
【问题描述】:
我有这个代码。
interface Test {
field1: string;
field2: string;
}
interface Test2 {
field3: string;
}
type TestResult = Partial<Test> & Test2;
const a = ():TestResult => {
return {};
}
这很正常,我的意思是,如果我在 obj 中没有 field3,它不会让我编译,但我没有得到 TestResult 上所有字段的推断,只有“部分和测试2”。 我的意思是,我如何实现智能感知,而不是显示它显示的“Partial & Test2”
field1: string;
field2: string;
field3: string;
这将是 TestResult 的实际结果
提前谢谢你
【问题讨论】:
标签: typescript intersection typescript-types