打字稿散布对象会自动与类型相交

时间:2020-05-05 10:22:27

标签: typescript

type a = { a: string }
type b = { b: string }
type c = { c: string }


const A: a = { a: "123" }
const C: c = { c: "789" }
const B: b = { b: "456", a: "123" }// ok, error as expected
const B2: b = { b: "456", a: "123", ...C } // ok, error as expected
const B3: b = { b: "456", a: "123", ...A } // what, why no error as if it is B3:a&b
const B4: b = { b: "456", a: "123", w:"2020", ...A } // only w:"2020" error

问题1:为什么B3没有抛出任何错误?

question2:如何解决此问题,如何使B3错误?

playground

0 个答案:

没有答案