feat: generics for InMemoryProvider Flag config#1046
Closed
wichopy wants to merge 1 commit intoopen-feature:mainfrom
Closed
feat: generics for InMemoryProvider Flag config#1046wichopy wants to merge 1 commit intoopen-feature:mainfrom
wichopy wants to merge 1 commit intoopen-feature:mainfrom
Conversation
Comment on lines
+36
to
53
| // sample | ||
| const flag: Flag<{ | ||
| hi: boolean, | ||
| bye: boolean, | ||
| }> = { | ||
| variants: { | ||
| 'hi': true, | ||
| bye: false, | ||
| }, | ||
| disabled: false, | ||
| defaultVariant: 'hi', | ||
| contextEvaluator: (ctx: EvaluationContext) => { | ||
| if (ctx.user === 'bob@flags.com') { | ||
| return 'bye'; | ||
| } | ||
| return 'hi'; | ||
| }, | ||
| }; |
Member
There was a problem hiding this comment.
I think this was there for testing?
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Apr 10, 2026
## This PR Applies _a few_ generics to the `Flag` and `FlagConfiguration` types used by `InMemoryProvider` to allow for type-safe variant values, ensuring the `defaultVariant` and any value returned by `contextEvaluator` are present as keys in `variants` for the given flag. ### Related Issues Resolves #967 Closes #1046 ### Notes If folks are passing in an object reference to `InMemoryProvider`, like we are in the specs, rather than an object literal directly, this is _technically_ a breaking change as they'll need to `as const` or pass it directly, to allow TypeScript to correctly infer the types. I'm personally of the opinion that this isn't a breaking change in the API of the package, and so this can ship as a minor change, but open to being told this should be considered breaking. Also, the monorepo is using a _very old_ version of TypeScript, 4.4, so I've had to include a util for `NoInfer` rather than using the built-in util that's available in TypeScript 5.4 and beyond. ### Follow-up Tasks N/A ### How to test See specs where this is already demonstrated to be working as I've had to apply `@ts-expect-error` when we're using invalid variant keys. --------- Signed-off-by: MattIPv4 <me@mattcowley.co.uk>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR
Related Issues
Fixes #1234523
Notes
Follow-up Tasks
How to test