Skip to main content

Type-Safe by Default

Grain SDK is written in TypeScript and includes complete type definitions:
No @types packages needed - types are built-in.

Configuration Types

Full type safety for configuration:
TypeScript catches invalid options at compile time.

Event Types

Type your event properties:
Or create typed track functions:

Template Event Types

Template methods have built-in types:

Custom Event Types

Create type-safe custom events:

React Hook Types

Hooks have full type inference:

Generic Client Type

For dependency injection or testing:

Strict Null Checks

SDK works with strict null checks:

Auth Provider Types

Type-safe auth providers:

Remote Config Types

Type your configurations:

Enum Event Names

Use enums for event names:
Autocomplete suggests valid event names.

Type Guards

Create type guards for safer code:

Exporting Types

Re-export types for your app:

Testing with Types

Type-safe testing:

Type-Safe Wrappers

Create type-safe wrappers for your domain:

Best Practices

1. Use Type Imports: Import only types when possible:
2. Define Event Interfaces: Type your event properties 3. Leverage Inference: Let TypeScript infer return types 4. Use Enums: For event names and categories 5. Strict Mode: Enable strict TypeScript checks

Next Steps

API Reference

See all available types

React Hooks

Type-safe React integration