Typescript: Notification.requestPermission()を追加してください

作成日 2015年05月11日  ·  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に入れないようにしています。

これらのAPIの定義を含む.d.tsファイルをいつでも自分で含めることができます。

Notification APIは実際には標準ではありませんか? https://notifications.spec.whatwg.org/

NotificationAPIはWebWorkersの一部であるため、標準ライブラリの1つで定義されることを期待しています(たとえば、新しいTS 1.9 --libオプションを使用)。

これは、 Notificationが標準からのものであった13か月以上前に閉鎖されました。

これは、TS-Lib-Generatorに貢献することで対処できます。

ありがとう@kitsonk貢献するためにTS-Lib-Generatorを調べましたが、 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>;
}

マスターを見ていませんが、まだ来ていないことに少し驚いています。 これはEdge14にあるため、EdgeのIDLはそれを反映する必要があり、オーバーライドなしで生成する必要があります...詳細については十分にわかりませんが、EdgeのIDLに追加すると、新しいAPIが自動的に表示されます。 IDLはビルド時に使用されます(リリースされただけですか)?

ああ、なるほど、ブラウザのIDLは現在4か月前のものです...つまり、「Edge13」のものである可能性が高いということです。 @zhengbliどのくらいの頻度で/いつ更新しますか?

以前は、公式のWindows 10リリースと一緒にEdge仕様ファイルを取得していたため、最後の更新は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[]
}

すごい仕事! 少し改善しました。Notificationクラスの「close」メソッドが欠落しており、非推奨の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-crayStackOverflowは質問の場所です。

@marcovdbは、スレッドの最後の投稿で言及されたコードとインターフェイスが異なる理由がありますか?

すみません、わかりません。 実際に定義を提供した人に尋ねる必要があります。 それは@zhengbliになります。

@zhengbliなぜNotificationOptions 5つを除いてすべてが省略されたのですか? 😞

@ialexryanは、新しい問題を提出し、問題に関するコンテキストを教えてください。喜んで調査させて

このページは役に立ちましたか?
0 / 5 - 0 評価