Skip to main content
Both packages ship their own type definitions. No @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 with GrainConfig. 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.
An 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.
Read Template events.

Typed configuration values

Remote configuration values are strings. Declare the keys once, then read them through a generic accessor.
The cast does not check the value at run time. A wrong value in the dashboard still arrives.

The client as a dependency

Type a constructor argument with GrainAnalytics to inject the client, or a mock of it.
In a test, jest.Mocked<GrainAnalytics> types the mock.

Auth provider

Null checks

The SDK compiles with strict: 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>.
Read React hooks.

Re-exporting types

Re-export the types that the app uses from one module, so that a package upgrade changes one import path.
Use import type for a type-only import. The bundler drops it from the output.