You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was just examining the API to look at adopting a feature-flagging standard and surprised to find that after defining a strict set of variants, there is no Typescript compiler error when providing a defaultVariant which is not in the list of variants. Similarly it is not a compiler error to return a random value for the variant from contextEvaluator.
Can these be made type-safe, please? There should be two compiler errors in the code below, and there are none. See playground
A workaround for type safety is to use a helper function like createVariant below, but to make the most of this, then InMemoryProvider should be defined as generic, to allow the const features of the configuration object passed to it to drive other parts of the API it exposes - e.g. flag names and variants are typed correspondingly when retrieved...
Hey @cefn, the InMemoryProvider was mainly built for demo and testing purposes. However, I can see the value of adding an additional type safety. I'll mark this as a Good First Issue.
Requirements
I was just examining the API to look at adopting a feature-flagging standard and surprised to find that after defining a strict set of variants, there is no Typescript compiler error when providing a
defaultVariant
which is not in the list of variants. Similarly it is not a compiler error to return a random value for the variant fromcontextEvaluator
.Can these be made type-safe, please? There should be two compiler errors in the code below, and there are none. See playground
A workaround for type safety is to use a helper function like
createVariant
below, but to make the most of this, then InMemoryProvider should be defined as generic, to allow the const features of the configuration object passed to it to drive other parts of the API it exposes - e.g. flag names and variants are typed correspondingly when retrieved...The text was updated successfully, but these errors were encountered: