feat: support type-safe flag keys via module augmentation#1349
feat: support type-safe flag keys via module augmentation#1349MattIPv4 wants to merge 3 commits intoopen-feature:mainfrom
Conversation
Summary of ChangesHello @MattIPv4, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the developer experience by integrating type-safe flag keys into the OpenFeature SDKs. By allowing module augmentation, it provides a flexible and powerful mechanism for developers to enforce strict typing on flag keys, leading to fewer runtime errors and better code maintainability. This change streamlines the process of working with feature flags by offering enhanced autocompletion and compile-time validation, making it easier to manage and evaluate flags correctly across different application environments. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
ca1ad14 to
ee798ab
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces comprehensive support for type-safe flag keys across the Angular, Nest, React, and Server SDKs, leveraging TypeScript module augmentation. The changes are well-implemented, consistently applying the new *FlagKey types and ConstrainedFlagKey where appropriate. The accompanying documentation updates in the README files clearly explain how consumers can utilize this new feature for enhanced type safety and autocompletion. This is a valuable improvement that will reduce common errors and improve developer experience.
ee798ab to
7fcdfaf
Compare
|
Wow, this is really neat! I'll try and test it locally but this seems like a solid approach. We may even be able to extend the OpenFeature CLI to optionally generate the declaration file. |
7fcdfaf to
ff7fcd6
Compare
|
Hey @MattIPv4, what's the best way to test this locally? |
|
I ended up building the packages and then installing them via file/link references in one of our actual projects that uses OpenFeature (and then following the README to add the augmentation to the project). I think you could probably spin up a very minimal TS project that just installs the web SDK w/ some fake You can also create a new directory |
|
This is rad |
There was a problem hiding this comment.
Thanks @MattIPv4!
This looks really cool!
I will do a proper test and review end of the weekend or beginning of next week :)
Signed-off-by: MattIPv4 <me@mattcowley.co.uk>
Signed-off-by: MattIPv4 <me@mattcowley.co.uk>
Signed-off-by: MattIPv4 <me@mattcowley.co.uk>
e81d87b to
222bff7
Compare
| * declare module '@openfeature/core' { | ||
| * export type StringFlagKey = 'my-string-flag'; | ||
| * } |
This PR
Adds support for consumers defining restricted types for flag keys when calling methods, via TypeScript module augmentation. Providing an alternative to using the CLI to code-gen type-safe wrapper hooks/methods.
Related Issues
Resolves #1341
Notes
My only concern would be whetherConstrainedFlagKeyis going to behave correctly for the generic methods likeuseFlag.Follow-up Tasks
N/A
How to test
I'm open to suggestions on how to encode tests for this in the repository itself. The notes in the READMEs shoud explain how one would test/use this as a consumer.