> For the complete documentation index, see [llms.txt](https://docs.dotpassport.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dotpassport.io/advanced/typescript.md).

# TypeScript Support

The SDK is written in TypeScript with complete type definitions.

## Type Imports

```typescript
import type {
  // Client types
  DotPassportConfig,
  DotPassportError,

  // Data types
  UserProfile,
  UserScores,
  UserBadges,
  CategoryScore,

  // Widget types
  WidgetConfig,
  ReputationWidgetConfig,
  BadgeWidgetConfig,
  ProfileWidgetConfig,
  CategoryWidgetConfig,

  // Definition types
  BadgeDefinition,
  CategoryDefinition
} from '@dotpassport/sdk';
```

## Type Safety

All methods are fully typed:

```typescript
const scores: UserScores = await client.getScores(address);
const badges: UserBadges = await client.getBadges(address);

// TypeScript will catch type errors
scores.totalScore;        // ✅ number
scores.invalidProperty;   // ❌ TypeScript error
```

## Generic Types

Client methods use generics for type inference:

```typescript
// Type is inferred automatically
const profile = await client.getProfile(address);
profile.displayName; // TypeScript knows this is a string

// Or explicitly specify types
const scores = await client.getScores<UserScores>(address);
```

## Widget Types

```typescript
import { createWidget, type WidgetConfig } from '@dotpassport/sdk';

const config: WidgetConfig = {
  apiKey: 'key',
  address: 'address',
  type: 'reputation'
};

const widget = createWidget(config);
```

## Custom Type Guards

```typescript
import { DotPassportError } from '@dotpassport/sdk';

function isDotPassportError(error: unknown): error is DotPassportError {
  return error instanceof DotPassportError;
}

try {
  await client.getScores(address);
} catch (error) {
  if (isDotPassportError(error)) {
    console.log(error.statusCode, error.message);
  }
}
```

## Next Steps

* [API Reference](/api-reference/api-reference.md)
* [Error Handling](https://github.com/dotpassport/dotpassport-sdk/blob/main/docs/api-client/error-handling.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.dotpassport.io/advanced/typescript.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
