@types package is needed. This page lists
the exported types and shows one example for each pattern. When this page and the types of the
published package disagree, the types win.
Exported types
@grainql/analytics-web:
@grainql/analytics-web/react:
@grainql/tag:
Read Types for the fields of each type.
Typed configuration
Annotate the configuration object withGrainConfig. The compiler rejects an unknown option
and a wrong authStrategy value.
Typed event properties
track accepts Record<string, unknown>. Wrap it in a function with a typed argument to get
a compile error on a wrong property.
enum works the same way for event names. Read Name events.
Template event types
Each template method has a property type. The compiler lists the valid fields.Typed configuration values
Remote configuration values are strings. Declare the keys once, then read them through a generic accessor.The client as a dependency
Type a constructor argument withGrainAnalytics to inject the client, or a mock of it.
jest.Mocked<GrainAnalytics> types the mock.
Auth provider
Null checks
The SDK compiles withstrict: true. getUserId() returns string | null, and getConfig
returns string | undefined. Test the value before you use it.
React hook results
The hooks return typed objects.useConfig gives value: string | undefined,
isRefreshing: boolean, error: Error | null, and refresh: () => Promise<void>.
Re-exporting types
Re-export the types that the app uses from one module, so that a package upgrade changes one import path.import type for a type-only import. The bundler drops it from the output.