1
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

questions1: why is B3 doesn't throw any error?

question2: how to solve this, how can I make B3 error?

playground

Acid Coder
  • 2,047
  • 15
  • 21
  • That's expected behaviour but I can't remember the reasoning. There was something about the spread operation which changed the types. I'll try to find more. – VLAZ May 05 '20 at 10:24
  • OK, can't find what I am thinking of. It *exists* but I can't seem to find the right search terms. Somebody who knows what's going on should show up, soon, I hope. – VLAZ May 05 '20 at 10:38
  • @AlekseyL. ...great, there are comments from me on that question liking to other questions I found. Apparently, I was more capable in the past than I am now. – VLAZ May 05 '20 at 10:47
  • @VLAZ I still can't find any proper docs on this besides this issue https://github.com/microsoft/TypeScript/issues/19775 – Aleksey L. May 05 '20 at 10:49

0 Answers0