Skip to content

Commit 99883c7

Browse files
authored
Merge pull request #134 from Flagsmith/chores/add_typescript_generics
Chores/add typescript generics
2 parents 935a0ce + eb26adc commit 99883c7

28 files changed

+216
-249
lines changed

examples/nextjs/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/nextjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12-
"flagsmith-es": "3.6.0",
12+
"flagsmith-es": "3.7.0",
1313
"lodash-es": "^4.17.21",
1414
"next": "12.1.0",
1515
"next-transpile-modules": "^9.0.0",

examples/nextjs/pages/_app.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import type { AppProps } from 'next/app';
33
import { FlagsmithProvider } from 'flagsmith-es/react';
44
import flagsmith from 'flagsmith-es/isomorphic';
55
import { IState } from 'flagsmith-es/types';
6+
67
const environmentID = "QjgYur4LQTwe5HpvbvhpzK"
8+
79
function MyApp({ Component, pageProps, flagsmithState }: AppProps & {flagsmithState: IState}) {
810
return (
911
<FlagsmithProvider flagsmith={flagsmith}

examples/nextjs/pages/index.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import type { NextPage } from 'next'
2-
import Head from 'next/head'
3-
import Image from 'next/image'
4-
import styles from '../styles/Home.module.css'
5-
import { useEffect } from 'react';
1+
import type { NextPage } from 'next';
62
import { useFlags, useFlagsmith } from 'flagsmith-es/react';
3+
import { FlagOptions } from '../types/flag-options';
4+
import { TraitOptions } from '../types/trait-options';
75

86
const Home: NextPage = () => {
9-
const flags = useFlags(["font_size"],["example_trait"]) // only causes re-render if specified flag values / traits change
10-
const flagsmith = useFlagsmith()
7+
const flags = useFlags<FlagOptions, TraitOptions>(["font_size"],["example_trait"]) // only causes re-render if specified flag values / traits change
8+
const flagsmith = useFlagsmith<FlagOptions, TraitOptions>()
119
const identify = ()=>{
1210
flagsmith.identify("flagsmith_sample_user")
1311
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type FlagOptions = "font_size" | "hero"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type TraitOptions = "example_trait"

flagsmith-es/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { IFlagsmith } from './types';
2-
declare const flagsmith: IFlagsmith;
2+
declare const flagsmith: IFlagsmith<string, string>;
33
export default flagsmith;
44
export declare const createFlagsmithInstance: () => IFlagsmith;

flagsmith-es/next-middleware.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { IFlagsmith } from './types';
2-
declare const flagsmith: IFlagsmith;
2+
declare const flagsmith: IFlagsmith<string, string>;
33
export default flagsmith;
44
export declare const createFlagsmithInstance: () => IFlagsmith;

flagsmith-es/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "flagsmith-es",
3-
"version": "3.6.0",
3+
"version": "3.7.0",
44
"description": "Feature flagging to support continuous development. This is an esm equivalent of the standard flagsmith npm module.",
55
"main": "./index.js",
66
"type": "module",

flagsmith-es/react/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import React, { FC } from 'react';
22
import { IFlagsmith, IFlagsmithTrait, IFlagsmithFeature, IState } from '../types';
3-
export declare const FlagsmithContext: React.Context<IFlagsmith>;
3+
export declare const FlagsmithContext: React.Context<IFlagsmith<string, string>>;
44
export declare type FlagsmithContextType = {
55
flagsmith: IFlagsmith;
66
options?: Parameters<IFlagsmith['init']>[0];
77
serverState?: IState;
88
children: React.ReactElement[] | React.ReactElement;
99
};
1010
export declare const FlagsmithProvider: FC<FlagsmithContextType>;
11-
export declare function useFlags<F extends string, T extends string>(_flags: readonly F[], _traits?: readonly T[]): {
11+
export declare function useFlags<F extends string = string, T extends string = string>(_flags: readonly F[], _traits?: readonly T[]): {
1212
[K in F]: IFlagsmithFeature;
1313
} & {
1414
[K in T]: IFlagsmithTrait;
1515
};
16-
export declare const useFlagsmith: () => IFlagsmith;
16+
export declare function useFlagsmith<F extends string = string, T extends string = string>(): IFlagsmith<F, T>;

0 commit comments

Comments
 (0)