v4.2.0 - Added optional TypeGuard to DynamicConfig get method
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.