TypeScript types for script tag installation
Contents
If you're loading PostHog via a <script> tag and want TypeScript types for window.posthog, you can install the @posthog/types package.
When to use this package
You need this package if:
You're loading PostHog via a <script> tag and want TypeScript types for window.posthog:
You don't need this package if:
You're installing any Javascript/Typescript PostHog library via npm, yarn, or pnpm. The types are already included:
| Package | Description |
|---|---|
posthog-js | Browser SDK |
posthog-js-lite | Lighter browser SDK (types are different) |
posthog-node | Node.js SDK |
posthog-react-native | React Native SDK |
@posthog/react | React hooks and components |
Installation
Usage
Typing window.posthog (script tag usage)
Create a type declaration file to type window.posthog:
Now you can use window.posthog with full type safety:
Typing configuration objects
You can also use the types to ensure your configuration objects are correctly typed:
Version synchronization
The @posthog/types package version is synchronized with posthog-js. They are always released together with matching version numbers, ensuring type definitions stay in sync with the SDK.