Skip to content

fix: typescript type generation when array of fields is passed. #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion react.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export declare type FlagsmithContextType<F extends string = string, T extends st
type UseFlagsReturn<
F extends string | Record<string, any>,
T extends string
> = F extends string
> = [F] extends [string]
? {
[K in F]: IFlagsmithFeature;
} & {
Expand Down
2 changes: 1 addition & 1 deletion react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function useFlagsmithLoading() {
type UseFlagsReturn<
F extends string | Record<string, any>,
T extends string
> = F extends string
> = [F] extends [string]
? {
[K in F]: IFlagsmithFeature;
} & {
Expand Down
8 changes: 4 additions & 4 deletions test/react-types.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import {render} from '@testing-library/react';
import {FlagsmithProvider, useFlags, useFlagsmith} from '../lib/flagsmith/react';
import {getFlagsmith,} from './test-constants';
import { IFlagsmithTrait } from '../types';
import { IFlagsmithFeature } from '../types';


describe.only('FlagsmithProvider', () => {
Expand Down Expand Up @@ -106,11 +106,11 @@ describe.only('FlagsmithProvider', () => {
const wrongTypedFlagsmith = useFlags<StringTypes>(["non-existing-flag"])

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const stringFlag: IFlagsmithTrait = typedFlagsmith.stringFlag
const stringFlag: IFlagsmithFeature = typedFlagsmith.stringFlag
//eslint-disable-next-line @typescript-eslint/no-unused-vars
const numberFlag: IFlagsmithTrait = typedFlagsmith.numberFlag
const numberFlag: IFlagsmithFeature = typedFlagsmith.numberFlag
//eslint-disable-next-line @typescript-eslint/no-unused-vars
const firstName: IFlagsmithTrait = typedFlagsmith.objectFlag
const firstName: IFlagsmithFeature = typedFlagsmith.objectFlag

return <></>
}
Expand Down