-
Notifications
You must be signed in to change notification settings - Fork 59
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Description
Currently, in the OpenFeature React SDK (@openfeature/react-sdk), the flagKey parameter in hooks such as useFlag, useBooleanFlag, useStringFlag, etc. is typed as a plain string.
This results in:
- no autocomplete for available flag keys,
- no compile-time validation for typos,
- potential drift between code and actual feature flag definitions.
It would be very valuable to have a way to make flagKey type-safe, for example via string literal types or generics.
Current behavior
useBooleanFlag('my-feature-flag');flagKey is typed as string, so TypeScript cannot:
- suggest valid keys,
- catch misspellings at compile time.
Desired behavior
Ability to restrict flagKey to a known set of feature flag keys:
type FeatureFlagKey =
| 'new-dashboard'
| 'beta-checkout'
| 'enable-ai';
useBooleanFlag('new-dashbord'); // ❌ TS error
useBooleanFlag('new-dashboard'); // ✅Or via a generic API:
useBooleanFlag<FeatureFlagKey>('new-dashboard');Possible approaches
-
Generic parameter for
flagKeyfunction useBooleanFlag<K extends string>( flagKey: K, defaultValue?: boolean ): boolean;
-
Typed provider / context
const FeatureFlagProvider = createFeatureFlagProvider<FeatureFlagKey>();
-
Module augmentation
Allow teams to extend flag key types in their own codebase without forking the SDK.
Why this matters
- Feature flags are part of business logic; mistakes in flag keys can be critical
- Type-safe flags:
- reduce runtime errors,
- improve developer experience,
- align well with contract-first approaches
- Especially valuable in large React codebases
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request