【发布时间】:2022-01-16 16:23:18
【问题描述】:
我想按照我的想法合并两个对象,但是typescript似乎只有一种合并对象的方法
type A = {
m: string;
n: number;
}
type B = {
n: string;
}
type C = B | A;
C 的结果类型是这样的
{
m: string;
n: number | string;
}
但我想要的是 A 只能代表分歧
//i want it is inValid
{
m: "hello",
n: "hi"
}
//other case is valid
{
m: "hello",
n: 1
}
{
n: "hello"
}
【问题讨论】:
-
这是否发生在函数的参数中?
-
我认为你遇到了这个问题:stackoverflow.com/questions/52677576/…
-
非常感谢您的帮助@TitianCernicova-Dragomir
标签: typescript types