Imagine we have an object x
representing type X
and an object y
representing type Y
.
Is there a way to combine (assign all properties) of y
into x
in such a way that if Y
is not a proper subset of X
, the compiler raises an error?
NOTE: While Object.assign(x, y)
can technically achieve this, it won't raise an error if Y
includes properties not found in X
.
I am seeking a method similar to {...x} = y
.
EDIT:
It's important to avoid reassignment to x
since that would change the identity of x
, which could be declared as const
.