statsig-io / react-sdk

An SDK for using Statsig Feature Management and Experimentation platform in React js clients
ISC License
6 stars 6 forks source link

Allow strict typing of `useGate()` gate parameter #14

Open jkjustjoshing opened 10 months ago

jkjustjoshing commented 10 months ago

Issue

If I fat-finger a gate ID when calling useGate(), I want my typescript type checker to identify this.

Suggestion

Make the gateName variable be a GateName type. This type is by default string, but can be overridden by the consuming project with something like

declare module 'statsig-react' {
  export type GateName = 'my_gate_1' | 'my_gate_2'
}

Whenever I start using a new gate, the first step is to add it to this type, and when I remove a type I remove it from this type definition.

tore-statsig commented 10 months ago

Thanks for the feedback!

This is a nice suggestion, I remember many people trying to maintain their own enums of gate names, and standardizing a way to do that would be nice. We've added this to our backlog