Closed toddbaert closed 2 years ago
Hi,
Could we do something like below:
export const OpenFeature: EvaluationLifeCycle = _OpenFeature;
//↑____ Error is thrown here when _OpenFeature doesn't implement the methods and properties from EvaluationLifeCycle
This approach does the job of enforcing the contract but I am not sure if this is the right way to achieve it.
I actually think the right approach might be to NOT export a class with static methods, but export an instance itself. That instance can be a class that we don't allow to be instantiated outside the API code.
I have worked on this. I have made the following changes:
Should I go ahead and raise a PR?
@anudeepreddy go ahead and open a PR. The only thing that sounds like it could be a problem is: made the getInstance static method public
.
I think instead I would just create an instance and make that the export. Then you are basically exporting a singleton, which should work I think.
Closed with https://github.com/open-feature/node-sdk/pull/44
The OpenFeature API object (class) implements the methods defined on
EvaluationLifeCycle
, but doesn't implement the interface, because static members cannot implement an interface (at least trivially). This means there could be drift between the hook methods on the client, and the API.We should find a solution for this, either with some typing magic, or by perhaps exporting an instance directly instead of using static methods.