function isConfigLoaded(value: string | undefined): value is string { return value !== undefined && value.length > 0;}const config = grain.getConfig('feature_flag');if (isConfigLoaded(config)) { // TypeScript knows config is string here console.log(config.toUpperCase());}
// types/analytics.tsexport type { GrainAnalytics, GrainConfig, GrainEvent, AuthProvider, LoginEventProperties, CheckoutEventProperties} from '@grainql/analytics-web';export type { UseConfigResult, UseAllConfigsResult} from '@grainql/analytics-web/react';
Copy
// components/MyComponent.tsximport type { UseConfigResult } from '@/types/analytics';
1. Use Type Imports: Import only types when possible:
Copy
import type { GrainConfig } from '@grainql/analytics-web';
2. Define Event Interfaces: Type your event properties3. Leverage Inference: Let TypeScript infer return types4. Use Enums: For event names and categories5. Strict Mode: Enable strict TypeScript checks