TypeScript
adsgram.d.ts dosyasını oluşturun ve types klasörüne veya mevcut tür tanımlamaları klasörüne ekleyin.
BİLGİ
Çerçeveye özgü npm paketlerimizi kullanıyorsanız (React veya Vue), TypeScript desteği kutudan çıkar çıkmaz dahildir ve manuel tür tanımlamalarına gerek yoktur.
AdsGram API Tür Tanımları
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 Projelerinde <adsgram-task> İçin Tür Tanımları
adsgram-task web bileşenini kullanmak için türleri tanımlamak üzere adsgram.d.ts dosyasına aşağıdaki kodu ekleyin:
ts
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
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 veya vanilla js için bu türleri eklemenize gerek yoktur.