I have an async store in Node.js, described by a type:
type IAsyncStore {
requestId: string;
startTime: Date;
userId: string;
endTime: Date;
}
and I want to have a function that updates a value:
static updateStore(key: keyof IAsyncStore, value: ???) {
// do some fancy action and update store
this._instance.store.run(this.getStore(), () => this.getStore()[key] = value
}
}
My idea was that I have for example key = “endTime”, the value must be of type Date. If I have requestId, the type of value must me string. Is there any way to accomplish this? Or do I have to write an overloaded method for this?
CodeSandbox
2