Typescript: الرجاء إضافة Notification.requestPermission ()

تم إنشاؤها على ١١ مايو ٢٠١٥  ·  19تعليقات  ·  مصدر: microsoft/TypeScript

التعليق الأكثر فائدة

بالمناسبة ، لقد قمت بعمل تعريف محدث لـ Notification :

type NotificationPermission = "default" | "denied"| "granted";

type NotificationDirection = "auto" | "ltr" | "rtl";

interface NotificationPermissionCallback {
    (permission: NotificationPermission): void;
}

interface NotificationOptions {
    dir?: NotificationDirection;
    lang?: string;
    body?: string;
    tag?: string;
    image?: string;
    icon?: string;
    badge?: string;
    sound?: string;
    vibrate?: number | number[],
    timestamp?: number,
    renotify?: boolean;
    silent?: boolean;
    requireInteraction?: boolean;
    data?: any;
    actions?: NotificationAction[]
}

interface NotificationAction {
    action: string;
    title: string;
    icon?: string;
}

declare class Notification extends EventTarget {
    constructor(title: string, options?: NotificationOptions);

    static readonly permission: NotificationPermission;
    static requestPermission(): Promise<NotificationPermission>;
    static requestPermission(deprecatedCallback: NotificationPermission): void;

    static readonly maxActions: number;

    onclick: EventListenerOrEventListenerObject;
    onerror: EventListenerOrEventListenerObject;

    readonly title: string;
    readonly dir: NotificationDirection;
    readonly lang: string;
    readonly body: string;
    readonly tag: string;
    readonly image: string;
    readonly icon: string;
    readonly badge: string;
    readonly sound: string;
    readonly vibrate: number[];
    readonly timestamp: number;
    readonly renotify: boolean;
    readonly silent: boolean;
    readonly requireInteraction: boolean;
    readonly data: any;
    readonly actions: NotificationAction[]
}

ال 19 كومينتر

نحاول ألا نضع الأشياء غير المعيارية في lib.d.ts.

يمكنك دائمًا تضمين ملف .d.ts بنفسك يتضمن تعريفات لواجهات برمجة التطبيقات هذه.

أليست Notification API في الواقع معيارًا؟ https://notifications.spec.whatwg.org/

نظرًا لأن Notification API هي جزء من Web Workers ، أتوقع أن يتم تعريفها في أحد libs القياسية (على سبيل المثال مع خيار TS 1.9 --lib ).

تم إغلاق هذا منذ أكثر من 13 شهرًا ، عندما كان Notification من المستوى القياسي.

يمكن معالجة ذلك من خلال المساهمة في TS-Lib-Generator .

شكرًا لك kitsonk لقد addedTypes.json (كما تنص إرشادات المساهمة) ، منذ تحتوي الواجهة على خصائص ثابتة / للقراءة فقط لا يغطيها البرنامج النصي للبناء.

هذا هو التصريح المطلوب:

interface NotificationOptions {
    dir?: DOMString;
    lang?: DOMString;
    body?: DOMString;
    tag?: DOMString;
    icon?: USVString;
    data?: any;
    vibrate?: number[];
    renotify?: boolean;
    silent?: boolean;
    sound?: USVString;
    noscreen?: boolean;
    sticky?: boolean;
}

interface Notification {
    readonly title: DOMString;
    readonly dir: DOMString;
    readonly lang: DOMString;
    readonly body: DOMString;
    readonly tag: DOMString;
    readonly icon: USVString;
    readonly data: any;
    readonly silent: boolean;
    readonly timestamp: DOMTimeStamp;
    readonly noscreen: boolean;
    readonly renotify: boolean;
    readonly sound: USVString;
    readonly sticky: boolean;
    readonly vibrate: number[];
    onclick: Function;
    onerror: Function;
    close(): void;
}

declare var Notification: {
    prototype: Notification;
    readonly permission: DOMString;
    new(title: string, options?: NotificationOptions): Notification;
    requestPermission(): Promise<DOMString>;
}

أنا مندهش قليلاً من أنه لم يأت بعد ، على الرغم من أنني لم أنظر إلى السيد. إنه موجود في Edge 14 ، لذا يجب أن تعكس IDLs لـ Edge ذلك ، والذي يجب أن يتم إنشاؤه بدون تجاوزات ... لا أعرف ما يكفي ، حول التفاصيل ، ولكن تظهر واجهات برمجة التطبيقات الجديدة تلقائيًا عند إضافتها إلى IDLs الخاصة بـ Edge وما هو إصدار يتم استخدام IDLs عند البناء (هل تم إصداره فقط)؟

آه ، أرى ، IDLs للمتصفح يبلغ عمرها حاليًا 4 أشهر ... مما يعني أنه من المحتمل أن يكونوا "Edge 13". zhengbli كم مرة / متى تقوم بتحديثها؟

اعتدنا على أخذ ملفات مواصفات Edge مع إصدارات Windows 10 الرسمية ، لذلك كان التحديث الأخير هو نفس TH2. ومع ذلك ، فمن المنطقي الآن إجراء تحديث أكثر تكرارًا لتجنب الجهود الضائعة من المجتمع ، فنحن ننتقل إلى فريق Edge في محاولة لإجراء تحديث شهري. أيضًا ، NotificationOptions متاح بالفعل في أحدث إصدار من Edge. يجب أن يتم تغطية التحديث القادم ، والذي يجب أن يكون قريبًا.

zhengbli هل هناك أي تحديث لهذه المشكلة؟

بالمناسبة ، لقد قمت بعمل تعريف محدث لـ Notification :

type NotificationPermission = "default" | "denied"| "granted";

type NotificationDirection = "auto" | "ltr" | "rtl";

interface NotificationPermissionCallback {
    (permission: NotificationPermission): void;
}

interface NotificationOptions {
    dir?: NotificationDirection;
    lang?: string;
    body?: string;
    tag?: string;
    image?: string;
    icon?: string;
    badge?: string;
    sound?: string;
    vibrate?: number | number[],
    timestamp?: number,
    renotify?: boolean;
    silent?: boolean;
    requireInteraction?: boolean;
    data?: any;
    actions?: NotificationAction[]
}

interface NotificationAction {
    action: string;
    title: string;
    icon?: string;
}

declare class Notification extends EventTarget {
    constructor(title: string, options?: NotificationOptions);

    static readonly permission: NotificationPermission;
    static requestPermission(): Promise<NotificationPermission>;
    static requestPermission(deprecatedCallback: NotificationPermission): void;

    static readonly maxActions: number;

    onclick: EventListenerOrEventListenerObject;
    onerror: EventListenerOrEventListenerObject;

    readonly title: string;
    readonly dir: NotificationDirection;
    readonly lang: string;
    readonly body: string;
    readonly tag: string;
    readonly image: string;
    readonly icon: string;
    readonly badge: string;
    readonly sound: string;
    readonly vibrate: number[];
    readonly timestamp: number;
    readonly renotify: boolean;
    readonly silent: boolean;
    readonly requireInteraction: boolean;
    readonly data: any;
    readonly actions: NotificationAction[]
}

عمل عظيم! لقد قمت بتحسينه قليلاً: طريقة "الإغلاق" في فئة الإخطار كانت مفقودة ، وتعريف أسلوب requestPermission المتوقف لم يكن صحيحًا تمامًا.

type NotificationPermission = "default" | "denied" | "granted";

type NotificationDirection = "auto" | "ltr" | "rtl";

interface NotificationPermissionCallback {
    (permission: NotificationPermission): void;
}

interface NotificationOptions {
    dir?: NotificationDirection;
    lang?: string;
    body?: string;
    tag?: string;
    image?: string;
    icon?: string;
    badge?: string;
    sound?: string;
    vibrate?: number | number[],
    timestamp?: number,
    renotify?: boolean;
    silent?: boolean;
    requireInteraction?: boolean;
    data?: any;
    actions?: NotificationAction[]
}

interface NotificationAction {
    action: string;
    title: string;
    icon?: string;
}

declare class Notification extends EventTarget {
    constructor(title: string, options?: NotificationOptions);

    static readonly permission: NotificationPermission;
    static requestPermission(): Promise<NotificationPermission>;
    static requestPermission(deprecatedCallback: (permission: NotificationPermission) => void): void;

    static readonly maxActions: number;

    onclick: EventListenerOrEventListenerObject;
    onerror: EventListenerOrEventListenerObject;

    close(): void;

    readonly title: string;
    readonly dir: NotificationDirection;
    readonly lang: string;
    readonly body: string;
    readonly tag: string;
    readonly image: string;
    readonly icon: string;
    readonly badge: string;
    readonly sound: string;
    readonly vibrate: number[];
    readonly timestamp: number;
    readonly renotify: boolean;
    readonly silent: boolean;
    readonly requireInteraction: boolean;
    readonly data: any;
    readonly actions: NotificationAction[]
}

كيف تشاهد نقرة العمل؟

@ mwent-cray StackOverflow هو المكان المناسب للأسئلة.

marcovdbmhegazy هل ما زالت تعريفات الإخطار في TS 2.4؟ لأنه لا يمكنني العثور عليه هناك: - |

https://github.com/Microsoft/TypeScript/blob/master/src/lib/dom.generated.d.ts

marcovdb هل هناك سبب لاختلاف الواجهة عن الكود المذكور في آخر مشاركة لك في الموضوع؟

آسف لا فكرة. عليك أن تسأل الشخص الذي ساهم بالفعل في التعريفات. سيكون ذلك zhengbli.

zhengbli لماذا تم NotificationOptions باستثناء 5؟ 😞

ialexryan ، يرجى تقديم مشكلة جديدة

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات

القضايا ذات الصلة

Antony-Jones picture Antony-Jones  ·  3تعليقات

weswigham picture weswigham  ·  3تعليقات

seanzer picture seanzer  ·  3تعليقات

Roam-Cooper picture Roam-Cooper  ·  3تعليقات

kyasbal-1994 picture kyasbal-1994  ·  3تعليقات