---
title: "TypeScript Tips"
url: "https://www.openstatus.dev/docs/sdk/nodejs/typescript-tips"
date: "2018-10-20"
author: "openstatus"
description: "Tips for working with bigint fields, oneof types, and migrating clients in the openstatus Node.js SDK"
category: "SDK"
agent:
  instructions: "Search openstatus docs, guides, blog and product pages. Replace {query} with URL-encoded keywords or a question. Returns markdown with links to matching pages, not a generated answer."
  endpoint: "https://www.openstatus.dev/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://www.openstatus.dev/.well-known/search"
---

## Working with bigint Fields

Protocol Buffers `int64` fields map to `bigint` in TypeScript. This affects:

- **Monitor configuration**: `timeout`, `retry`, `degradedAt`
- **Assertions**: `StatusCodeAssertion.target`
- **Monitor summary**: `totalSuccessful`, `totalDegraded`, `totalFailed`, `p50`, `p75`, `p90`, `p95`, `p99`

Use `BigInt()` to create values:

```typescript
const { monitor } = await client.monitor.v1.MonitorService.createHTTPMonitor({
  monitor: {
    name: "My API",
    url: "https://example.com",
    method: HTTPMethod.HTTP_METHOD_GET,
    periodicity: Periodicity.PERIODICITY_1M,
    active: true,
    timeout: BigInt(30000),       // 30 seconds
    retry: BigInt(5),             // 5 attempts in total
    degradedAt: BigInt(3000),     // degraded after 3s
    statusCodeAssertions: [
      { comparator: NumberComparator.EQUAL, target: BigInt(200) },
    ],
  },
});
```

Reading bigint values:

```typescript
const summary = await client.monitor.v1.MonitorService.getMonitorSummary({
  id: "123456",
  timeRange: TimeRange.TIME_RANGE_7D,
  regions: [],
});

// bigint values — use Number() for display if values are safe
console.log(`P95 latency: ${summary.p95}ms`);
console.log(`Total checks: ${summary.totalSuccessful + summary.totalDegraded + summary.totalFailed}`);
```

## Handling oneof Types

Several responses use protobuf `oneof` fields, which map to discriminated unions in TypeScript.

### MonitorConfig (getMonitor)

```typescript
const { monitor } = await client.monitor.v1.MonitorService.getMonitor({
  id: "123456",
});

switch (monitor?.config.case) {
  case "http":
    // monitor.config.value is HTTPMonitor
    console.log(`URL: ${monitor.config.value.url}`);
    break;
  case "tcp":
    // monitor.config.value is TCPMonitor
    console.log(`URI: ${monitor.config.value.uri}`);
    break;
  case "dns":
    // monitor.config.value is DNSMonitor
    console.log(`Domain: ${monitor.config.value.uri}`);
    break;
}
```

### NotificationData (createNotification)

The `data.data` field selects the provider-specific configuration:

```typescript
// The case string matches the provider in camelCase
data: {
  data: { case: "slack", value: { webhookUrl: "..." } }
}
data: {
  data: { case: "googleChat", value: { webhookUrl: "..." } }
}
data: {
  data: { case: "grafanaOncall", value: { webhookUrl: "..." } }
}
```

### Status Page Identifiers

`getStatusPageContent` and `getOverallStatus` accept a page identifier by ID or slug:

```typescript
// By ID
{ identifier: { case: "id", value: "page_123" } }

// By slug
{ identifier: { case: "slug", value: "my-service" } }
```

### Unsubscribe Identifier

`unsubscribeFromPage` accepts an email or subscriber ID:

```typescript
// By email
{ identifier: { case: "email", value: "user@example.com" } }

// By subscriber ID
{ identifier: { case: "id", value: "sub_456" } }
```

## Migrating from Default Client to createOpenStatusClient

**Before** — manual headers on every call:

```typescript

const headers = { "x-openstatus-key": process.env.OPENSTATUS_API_KEY };

const { httpMonitors } = await openstatus.monitor.v1.MonitorService
  .listMonitors({}, { headers });

const { monitor } = await openstatus.monitor.v1.MonitorService
  .createHTTPMonitor({
    monitor: { name: "API", url: "https://example.com", method: 1, periodicity: 2, active: true },
  }, { headers });
```

**After** — configure once, use everywhere:

```typescript

const client = createOpenStatusClient({
  apiKey: process.env.OPENSTATUS_API_KEY,
});

const { httpMonitors } = await client.monitor.v1.MonitorService
  .listMonitors({});

const { monitor } = await client.monitor.v1.MonitorService
  .createHTTPMonitor({
    monitor: {
      name: "API",
      url: "https://example.com",
      method: HTTPMethod.HTTP_METHOD_GET,
      periodicity: Periodicity.PERIODICITY_1M,
      active: true,
    },
  });
```