Files
supabase/apps/studio/hooks/misc/useIsFeatureEnabled.ts
Alaister YoungandAlaister Young a47397d5fe fix(common): restore narrow Feature type (#50850)
The platform API now types `ProfileResponse.disabled_features` as
`string[]` (since #48981), which collapsed the `Feature` union to plain
`string`, so `isFeatureEnabled` accepted any string and typos went
uncaught.

**Changed:**
- `Feature` is now a local `RuntimeFeature` union (the profile-driven
flags) plus the keys of `enabled-features.json`, instead of deriving
from the API type
- `useIsFeatureEnabled` casts the merged runtime disabled list to
`Feature[]`, since the profile field is now `string[]`

The runtime feature list duplicates what the backend knows. Once the
enum is restored in the API spec, `Feature` can go back to deriving from
the generated type.

## To test

- `pnpm typecheck` passes
- Passing a bogus string to `useIsFeatureEnabled` / `isFeatureEnabled`
is now a type error
- Nothing behavioral changes, so a quick sanity check that the sidebar /
billing / org settings still render is enough


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **No user-facing changes**
* This update does not change the app’s visible features or behavior. It
includes internal typing adjustments only.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-09-25 17:21:38 +10:00

29 lines
1012 B
TypeScript

import { isFeatureEnabled, type Feature } from 'common'
import { useEnabledFeaturesOverrideQuery } from '@/data/misc/enabled-features-override-query'
import { useProfile } from '@/lib/profile'
function useIsFeatureEnabled<T extends Feature[]>(
features: T
): ReturnType<typeof isFeatureEnabled<T>>
function useIsFeatureEnabled(features: Feature): ReturnType<typeof isFeatureEnabled>
function useIsFeatureEnabled<T extends Feature | Feature[]>(features: T) {
const { profile } = useProfile()
const { data: override } = useEnabledFeaturesOverrideQuery()
const disabledFeatures = [
...(profile?.disabled_features ?? []),
...(override?.disabled_features ?? []),
] as Feature[]
// This code branch is to make the type checker happy, it's intentionally
// the same as the isFeatureEnabled function call below.
if (Array.isArray(features)) {
return isFeatureEnabled(features, disabledFeatures)
}
return isFeatureEnabled(features, disabledFeatures)
}
export { useIsFeatureEnabled }