Skip to content

Commit 172b586

Browse files
author
Rushi Bhargav
committed
fix: typescript type generation when array of fields is passed.
* Changed conditional type generation from distributive to non-distributive
1 parent f57c9ed commit 172b586

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

react.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export declare type FlagsmithContextType<F extends string = string, T extends st
1111
type UseFlagsReturn<
1212
F extends string | Record<string, any>,
1313
T extends string
14-
> = F extends string
14+
> = [F] extends [string]
1515
? {
1616
[K in F]: IFlagsmithFeature;
1717
} & {

react.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export function useFlagsmithLoading() {
129129
type UseFlagsReturn<
130130
F extends string | Record<string, any>,
131131
T extends string
132-
> = F extends string
132+
> = [F] extends [string]
133133
? {
134134
[K in F]: IFlagsmithFeature;
135135
} & {

test/react-types.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import {render} from '@testing-library/react';
33
import {FlagsmithProvider, useFlags, useFlagsmith} from '../lib/flagsmith/react';
44
import {getFlagsmith,} from './test-constants';
5-
import { IFlagsmithTrait } from '../types';
5+
import { IFlagsmithFeature } from '../types';
66

77

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

108108
// eslint-disable-next-line @typescript-eslint/no-unused-vars
109-
const stringFlag: IFlagsmithTrait = typedFlagsmith.stringFlag
109+
const stringFlag: IFlagsmithFeature = typedFlagsmith.stringFlag
110110
//eslint-disable-next-line @typescript-eslint/no-unused-vars
111-
const numberFlag: IFlagsmithTrait = typedFlagsmith.numberFlag
111+
const numberFlag: IFlagsmithFeature = typedFlagsmith.numberFlag
112112
//eslint-disable-next-line @typescript-eslint/no-unused-vars
113-
const firstName: IFlagsmithTrait = typedFlagsmith.objectFlag
113+
const firstName: IFlagsmithFeature = typedFlagsmith.objectFlag
114114

115115
return <></>
116116
}

0 commit comments

Comments
 (0)