Two mysterious (generic) nested objects with a similar structure are in play:
const A = {
one: {
two: {
three: {
func1: () => null,
},
},
},
}
const B = {
one: {
two: {
three: {
func2: () => null,
},
},
},
}
A type needs to be created that combines them so that both func1
AND func2
coexist inside one.two.three
, but with only properties of A referenced by one
, two
, and three
.
Intersections come close, but aren't the exact solution. When performing this task:
const C: typeof A & typeof B = {}
C.one.two.three.func1() // Valid
C.one.two.three.func2() // Valid
Both functions should appear as values within three
. However, each shared property currently points back to both A and B, when it should solely reference A.
For instance, clicking on the definition of three
from variable C reveals two possible definitions (A and B), when Typescript should prioritize A and lead to the corresponding section. But for func2
, the jump should target its creation point in B.