# @posthog/types

> Type definitions for the PostHog JavaScript SDK

Latest version **1.411.1** (published 2026-09-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @posthog/types
pnpm add @posthog/types
yarn add @posthog/types
bun add @posthog/types
```

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.411.1 |
| Published | 2026-09-11 |
| First published | 2026-01-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 605 |
| Maintainers | fuziontech, mariusandra, ben-posthog, timgl, rafael_posthog, fraserhopper, manoelposthog, robbie-c, gustavostrassburger, dustinbyrne, feliperalmeida, lucasheriques, frankposthog, tom-posthog, adamleithp, cat-ph, sarahxsanders, peterkirkhamposthog, ioannisj, joshuasnyder, huguespouillot |

## Links

- npm: https://www.npmjs.com/package/@posthog/types
- Repository: https://github.com/PostHog/posthog-js
- Issues: https://github.com/PostHog/posthog-js/issues
- npm.io page: https://npm.io/package/@posthog/types

## Recent versions

- 1.411.1 (latest) — 2026-09-11
- 1.411.0 — 2026-09-10
- 1.410.1 — 2026-09-10
- 1.410.0 — 2026-09-09
- 1.409.4 — 2026-09-09
- 1.409.3 — 2026-09-09
- 1.409.2 — 2026-09-08
- 1.409.1 — 2026-09-07
- 1.409.0 — 2026-09-04
- 1.408.1 — 2026-09-03
- 1.408.0 — 2026-09-02
- 1.407.2 — 2026-09-01
- 1.407.1 — 2026-08-28
- 1.407.0 — 2026-08-26
- 1.406.2 — 2026-08-26
- … 240 more at https://npm.io/package/@posthog/types/versions

## README

# @posthog/types

Type definitions for the PostHog JavaScript SDK.

## 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`.

```html
<!-- You load PostHog like this -->
<script>
    !function(t,e){...}(document,window.posthog||[]);
    posthog.init('your-api-key', { api_host: 'https://us.i.posthog.com' })
</script>
```

### ❌ You Don't Need This Package If:

You're installing any PostHog library via npm/yarn/pnpm. The types are **already included**:

- `posthog-js` - Browser SDK (includes all types)
- `posthog-node` - Node.js SDK
- `posthog-react-native` - React Native SDK
- `@posthog/react` - React hooks and components

```typescript
// Types are already available when you install posthog-js
import posthog from 'posthog-js'

posthog.init('your-api-key')
posthog.capture('my_event') // ✅ Fully typed
```

## Installation

```bash
npm install @posthog/types
# or
yarn add @posthog/types
# or
pnpm add @posthog/types
```

## Usage

### Typing `window.posthog` (Script Tag Usage)

Create a type declaration file to type `window.posthog`:

```typescript
// posthog.d.ts
import type { PostHog } from '@posthog/types'

declare global {
    interface Window {
        posthog?: PostHog
    }
}

export {}
```

Now you can use `window.posthog` with full type safety:

```typescript
// Your code
window.posthog?.capture('button_clicked', { button_id: 'signup' })
window.posthog?.identify('user-123', { email: 'user@example.com' })

const flagValue = window.posthog?.getFeatureFlag('my-flag')
if (flagValue === 'variant-a') {
    // ...
}
```

### Typing Configuration Objects

```typescript
import type { PostHogConfig, Properties } from '@posthog/types'

// Type your configuration
const config: Partial<PostHogConfig> = {
    api_host: 'https://us.i.posthog.com',
    autocapture: true,
    capture_pageview: 'history_change',
}

// Type event properties
const eventProps: Properties = {
    button_id: 'signup',
    page: '/pricing',
}
```

## Version Synchronization

This package's version is synchronized with `posthog-js`. They are always released together with matching version numbers.

## License

MIT

---
_Source: https://npm.io/package/@posthog/types · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
