@@ -3,34 +3,33 @@ export interface IFlagsmithFeature {
33 value ?: string | number | boolean ;
44}
55export declare type IFlagsmithTrait = string | number | boolean ;
6- export interface IFlags {
7- [ key : string ] : IFlagsmithFeature ;
8- }
9- export interface ITraits {
10- [ key : string ] : IFlagsmithTrait ;
11- }
6+
7+ export type IFlags < F extends string = string > = Record < F , IFlagsmithFeature > ;
8+
9+ export type ITraits < T extends string = string > = Record < T , IFlagsmithTrait > ;
10+
1211export interface IRetrieveInfo {
1312 isFromServer : boolean ;
1413 flagsChanged : boolean ;
1514 traitsChanged : boolean ;
1615}
17- export interface IState {
16+ export interface IState < F extends string = string , T extends string = string > {
1817 api : string ;
1918 environmentID : string ;
20- flags ?: IFlags ;
19+ flags ?: IFlags < F > ;
2120 identity ?: string ;
22- traits : ITraits ;
21+ traits : ITraits < T > ;
2322}
2423declare type ICacheOptions = {
2524 ttl ?: number ;
2625 skipAPI ?: boolean ;
2726} ;
28- export interface IInitConfig {
27+ export interface IInitConfig < F extends string = string , T extends string = string > {
2928 AsyncStorage ?: any ;
3029 api ?: string ;
3130 cacheFlags ?: boolean ;
3231 cacheOptions ?: ICacheOptions ;
33- defaultFlags ?: IFlags ;
32+ defaultFlags ?: Partial < IFlags < F > > ;
3433 fetch ?: any ;
3534 enableAnalytics ?: boolean ;
3635 enableDynatrace ?: boolean ;
@@ -39,28 +38,28 @@ export interface IInitConfig {
3938 environmentID : string ;
4039 headers ?: object ;
4140 identity ?: string ;
42- traits ?: ITraits ;
43- onChange ?: ( previousFlags : IFlags , params : IRetrieveInfo ) => void ;
41+ traits ?: ITraits < T > ;
42+ onChange ?: ( previousFlags : IFlags < F > , params : IRetrieveInfo ) => void ;
4443 onError ?: ( res : {
4544 message : string ;
4645 } ) => void ;
4746 preventFetch ?: boolean ;
4847 state ?: IState ;
4948 _trigger ?: ( ) => void ;
5049}
51- export interface IFlagsmith {
50+ export interface IFlagsmith < F extends string = string , T extends string = string > {
5251 /**
5352 * Initialise the sdk against a particular environment
5453 */
55- init : ( config : IInitConfig ) => Promise < void > ;
54+ init : ( config : IInitConfig < F , T > ) => Promise < void > ;
5655 /**
5756 * Trigger a manual fetch of the environment features
5857 */
5958 getFlags : ( ) => Promise < null > ;
6059 /**
6160 * Returns the current flags
6261 */
63- getAllFlags : ( ) => IFlags ;
62+ getAllFlags : ( ) => IFlags < F > ;
6463 /**
6564 * Identify user, triggers a call to get flags if flagsmith.init has been called
6665 */
@@ -88,23 +87,23 @@ export interface IFlagsmith {
8887 /**
8988 * Get the whether a flag is enabled e.g. flagsmith.hasFeature("powerUserFeature")
9089 */
91- hasFeature : ( key : string ) => boolean ;
90+ hasFeature : ( key : F ) => boolean ;
9291 /**
9392 * Get the value of a particular remote config e.g. flagsmith.getValue("font_size")
9493 */
95- getValue : ( key : string ) => string | number | boolean ;
94+ getValue : ( key : F ) => string | number | boolean ;
9695 /**
9796 * Get the value of a particular trait for the identified user
9897 */
99- getTrait : ( key : string ) => string | number | boolean ;
98+ getTrait : ( key : T ) => string | number | boolean ;
10099 /**
101100 * Set a specific trait for a given user id, triggers a call to get flags
102101 */
103- setTrait : ( key : string , value : string | number | boolean ) => Promise < null > ;
102+ setTrait : ( key : T , value : string | number | boolean ) => Promise < null > ;
104103 /**
105104 * Set a key value set of traits for a given user, triggers a call to get flags
106105 */
107- setTraits : ( traits : Record < string , string | number | boolean > ) => Promise < null > ;
106+ setTraits : ( traits : Record < T , string | number | boolean > ) => Promise < null > ;
108107 /**
109108 * The stored identity of the user
110109 */
0 commit comments