How can I self reference a prop in typescript?
const Test = {
a: { someProp: true },
b: { ...Test.a, someOtherProp: true } //error: Block-scoped variable 'Test' used before its declaration.
}
here is a Playground Link
Use a getter:
const Test = {
a: { someProp: true },
get b() {
return { ...Test.a, someOtherProp: true }
}
}
(This problem is not specific to TypeScript—it's how JavaScript works)