Skip to content

v4.2.0 - Added optional TypeGuard to DynamicConfig get method

Choose a tag to compare

@jkw-statsig jkw-statsig released this 08 Dec 21:24
· 37 commits to main since this release
e089f64

In this release we are adding an optional TypeGuard parameter to the get<T> method on DynamicConfig class, so that users can use their own TypeGuard functions to ensure type correctness. Thanks to Statsig user @bilalq for his idea and contribution on this!

interface Thing {
  category: 'real' | 'imaginary'
}

const isThing = (obj: any): obj is Thing => {
  return obj?.category === 'real' || obj?.category === 'imaginary'
}

...

const config = useConfig('my_config');
const defaultThing: Thing = { category: 'real' };
const myThing = config.get('my_thing', defaultThing, isThing);

// myThing is now guaranteed to be a Thing, instead of any kind of object.