As I am just starting to learn Typescript, please excuse me if this question is not well-formed.
I have an object (Object A) that encapsulates another object (Object B) and includes some methods to manipulate Object B. My goal is to proxy the access on Object A so when accessing a key, the corresponding value from Object B will be returned. To illustrate, consider the following code snippet:
type AType = {
state: StateType
doubleSomeVal(): number;
} & StateType
type StateType = {
someVal: number;
}
type StateTypeKey = "someVal"
class A implements AType {
state: StateType;
doubleSomeVal() {
return this.state.someVal * 2;
}
constructor(state: StateType) {
this.state = state;
}
static create(state: StateType) {
return new Proxy(new A(state), {
get(target: A, key: StateTypeKey) {
return target.state[key] || target[key];
}
});
}
}
However, TypeScript raises an error because it does not recognize that my class A possesses the properties of StateType - which is understandable, but I would like to address this issue if possible.