Commit f5ccadf0 authored by tom's avatar tom

better typing

parent 2c18ad2f
...@@ -3,6 +3,10 @@ import { GrowthBook } from '@growthbook/growthbook-react'; ...@@ -3,6 +3,10 @@ import { GrowthBook } from '@growthbook/growthbook-react';
import config from 'configs/app'; import config from 'configs/app';
import * as mixpanel from 'lib/mixpanel'; import * as mixpanel from 'lib/mixpanel';
export interface GrowthBookFeatures {
test_value: string;
}
export const growthBook = (() => { export const growthBook = (() => {
const feature = config.features.growthBook; const feature = config.features.growthBook;
...@@ -10,7 +14,7 @@ export const growthBook = (() => { ...@@ -10,7 +14,7 @@ export const growthBook = (() => {
return; return;
} }
return new GrowthBook({ return new GrowthBook<GrowthBookFeatures>({
apiHost: 'https://cdn.growthbook.io', apiHost: 'https://cdn.growthbook.io',
clientKey: feature.clientKey, clientKey: feature.clientKey,
enableDevMode: config.app.isDev, enableDevMode: config.app.isDev,
......
import type { WidenPrimitives } from '@growthbook/growthbook';
import { useFeatureValue, useGrowthBook } from '@growthbook/growthbook-react'; import { useFeatureValue, useGrowthBook } from '@growthbook/growthbook-react';
export default function useGbFeatureValue<T extends Parameters<typeof useFeatureValue>[1]>( import type { GrowthBookFeatures } from './init';
name: Parameters<typeof useFeatureValue>[0],
fallback: T, export default function useGbFeatureValue<Name extends keyof GrowthBookFeatures>(
): { value: ReturnType<typeof useFeatureValue<T>>; isLoading: boolean } { name: Name,
fallback: GrowthBookFeatures[Name],
): { value: WidenPrimitives<GrowthBookFeatures[Name]>; isLoading: boolean } {
const value = useFeatureValue(name, fallback); const value = useFeatureValue(name, fallback);
const growthBook = useGrowthBook(); const growthBook = useGrowthBook();
......
...@@ -30,7 +30,7 @@ export default function useMixpanelInit() { ...@@ -30,7 +30,7 @@ export default function useMixpanelInit() {
loaded: function() { loaded: function() {
growthBook?.setAttributes({ growthBook?.setAttributes({
...growthBook.getAttributes(), ...growthBook.getAttributes(),
time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone, timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
language: window.navigator.language, language: window.navigator.language,
}); });
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment