Skip to content

Commit f57c9ed

Browse files
authored
fix(types): Align FlagsmithProvider children prop type with React.ReactNode (#317)
Ensures the `children` prop in `FlagsmithProvider`'s type definition (`FlagsmithContextType`) is correctly set to `React.ReactNode` in both the implementation (`react.tsx`) and the declaration file (`react.d.ts`). Adds a type test to verify that `FlagsmithProvider` compiles successfully when provided with a plain string child, which is a valid `React.ReactNode`. This test would fail compilation if the type were incorrectly restricted (e.g., to `ReactElement | ReactElement[]`).
1 parent ce0412b commit f57c9ed

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

react.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export declare type FlagsmithContextType<F extends string = string, T extends st
66
flagsmith: IFlagsmith<F, T>;
77
options?: Parameters<IFlagsmith<F, T>['init']>[0];
88
serverState?: IState;
9-
children: React.ReactElement[] | React.ReactElement;
9+
children: React.ReactNode;
1010
};
1111
type UseFlagsReturn<
1212
F extends string | Record<string, any>,

test/react-types.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,15 @@ describe.only('FlagsmithProvider', () => {
122122
</FlagsmithProvider>
123123
);
124124
});
125+
it('should compile if children prop is React.ReactNode', () => {
126+
const { flagsmith, initConfig } = getFlagsmith();
127+
const children: React.ReactNode = "I am a ReactNode child";
128+
const { container } = render(
129+
<FlagsmithProvider flagsmith={flagsmith} options={initConfig}>
130+
{children}
131+
</FlagsmithProvider>
132+
);
133+
134+
expect(container.textContent).toBe(children);
135+
});
125136
});

0 commit comments

Comments
 (0)