---
title: "AdsGram के लिए TypeScript टाइप्स"
description: "AdsGram SDK के लिए TypeScript टाइप डिक्लेरेशन: AdController, ShowPromiseResult, इवेंट टाइप्स और adsgram-task कॉम्पोनेंट की टाइपिंग।"
---

# Typescript

`adsgram.d.ts` फ़ाइल बनाएं और इसे `types` फ़ोल्डर या मौजूदा टाइप घोषणा फ़ोल्डर में जोड़ें।

::: info जानकारी
यदि आप हमारे फ्रेमवर्क-विशिष्ट npm पैकेज ([React](https://www.npmjs.com/package/@adsgram/react) या [Vue](https://www.npmjs.com/package/@adsgram/vue)) का उपयोग कर रहे हैं, तो TypeScript समर्थन पहले से ही बॉक्स में शामिल है और मैन्युअल टाइप घोषणा की आवश्यकता नहीं है।
:::

## 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;
      };
    }
}
```
:::

## React/preact प्रोजेक्ट में `<adsgram-task>` के लिए टाइपिंग{#task-types}
`adsgram.d.ts` में निम्न कोड जोड़ें ताकि वेब कंपोनेंट `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;
    }
  }
}
```
:::

`.vue` या vanilla js के लिए टाइपिंग जोड़ने की आवश्यकता नहीं है।
