---
title: "AdsGram TypeScript Types"
description: "TypeScript type declarations for the AdsGram SDK: AdController, ShowPromiseResult, event types, and typings for the adsgram-task component."
---

# Typescript

Create `adsgram.d.ts` file and add it to `types` folder or existing folder with types declarations.

::: info
If you're using our framework-specific npm packages ([React](https://www.npmjs.com/package/@adsgram/react) or [Vue](https://www.npmjs.com/package/@adsgram/vue)), TypeScript support is included out of the box and no manual type declarations are needed.
:::

## AdsGram API Typing
::: code-group
```ts [adsgram.d.ts]
export interface ShowPromiseResult {
  done: boolean;
  description: string;
  state: 'load' | 'render' | 'playing' | 'destroy';
  error: boolean;
}

type BannerType = 'RewardedVideo' | 'FullscreenMedia';

interface AdsgramInitParams {
  blockId: string;
  debug?: boolean;
  debugConsole?: boolean;
  debugBannerType?: BannerType;
}

type EventType =
  | 'onReward'
  | 'onComplete'
  | 'onStart'
  | 'onSkip'
  | 'onBannerNotFound'
  | 'onNonStopShow'
  | 'onTooLongSession'
  | 'onError';
type HandlerType = () => void;

export interface AdController {
  show(): Promise<ShowPromiseResult>;
  addEventListener(event: EventType, handler: HandlerType): void;
  removeEventListener(event: EventType, handler: HandlerType): void;
  destroy(): void;
}

declare global {
    interface Window {
      Adsgram?: {
        init(params: AdsgramInitParams): AdController;
      };
    }
}
```
:::


## Typing for the `<adsgram-task>` in react/preact projects{#task-types}
Add the following code to `adsgram.d.ts` to describe the types for using the web component `adsgram-task`:
::: code-group
```ts [adsgram.d.ts (react)]
import type { DetailedHTMLProps, HTMLAttributes } from "react";

type AdsgramTaskAttributes = DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement> & {
  "data-block-id": string;
  "data-debug"?: boolean | "true" | "false";
  "data-debug-console"?: boolean | "true" | "false";
  classname?: string;
};

declare module "react" {
  namespace JSX {
    interface IntrinsicElements {
      "adsgram-task": AdsgramTaskAttributes;
    }
  }
}
```
```ts [adsgram.d.ts (preact)]
import type { JSX } from "preact";

type AdsgramTaskAttributes = JSX.HTMLAttributes<HTMLElement> & {
  "data-block-id": string;
  "data-debug"?: boolean | "true" | "false";
  "data-debug-console"?: boolean | "true" | "false";
  classname?: string;
};

declare module "preact" {
  namespace JSX {
    interface IntrinsicElements {
      "adsgram-task": AdsgramTaskAttributes;
    }
  }
}
```
:::

There is no need to add these types for vue or vanilla js.
