Typescript: Bitte fügen Sie Notification.requestPermission () hinzu

Erstellt am 11. Mai 2015  ·  19Kommentare  ·  Quelle: microsoft/TypeScript

Hilfreichster Kommentar

Übrigens habe ich eine aktualisierte Definition für 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[]
}

Alle 19 Kommentare

Wir versuchen, nicht standardisierte Dinge nicht in lib.d.ts zu setzen.

Sie können jederzeit selbst eine .d.ts-Datei einfügen, die Definitionen für diese APIs enthält.

Ist die Benachrichtigungs-API nicht tatsächlich ein Standard? https://notifications.spec.whatwg.org/

Da die Benachrichtigungs-API Teil von Web Workers ist, würde ich erwarten, dass sie in einer der Standardbibliotheken definiert wird (z. B. mit der neuen Option TS 1.9 --lib ).

Dies wurde vor über 13 Monaten geschlossen, als Notification vom Standard war.

Dies kann durch einen Beitrag zum TS-Lib-Generator behoben werden .

Vielen Dank @kitsonk Ich habe einen Blick auf den TS-Lib-Generator addedTypes.json eingefügt werden soll (wie in den Beitragsrichtlinien angegeben) Die Schnittstelle verfügt über statische / schreibgeschützte Eigenschaften, die vom Build-Skript nicht abgedeckt werden.

Dies ist die erforderliche Erklärung:

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>;
}

Ich bin ein bisschen überrascht, dass es noch nicht vorbei ist, obwohl ich den Meister nicht angesehen habe. Es befindet sich in Edge 14, daher sollten die IDLs für Edge das widerspiegeln, was es ohne Überschreibungen generieren sollte ... Ich weiß nicht genug über die Besonderheiten, aber neue APIs werden automatisch angezeigt, wenn sie zu den IDLs von Edge hinzugefügt werden und von welcher Version Die IDLs werden beim Erstellen verwendet (wird es nur freigegeben)?

Ah, ich verstehe, die Browser-IDLs sind derzeit 4 Monate alt ... was bedeutet, dass es wahrscheinlich "Edge 13" sind. @zhengbli wie oft / wann aktualisierst du sie?

Wir haben die Edge-Spezifikationsdateien zusammen mit offiziellen Windows 10-Versionen verwendet, daher war das letzte Update das gleiche wie TH2. Es ist jetzt jedoch sinnvoller, ein häufigeres Update durchzuführen, um unnötige Anstrengungen der Community zu vermeiden. Wir wenden uns an das Edge-Team, um ein monatliches Update durchzuführen. Außerdem ist NotificationOptions im neuesten Edge-Build tatsächlich verfügbar. Es sollte das nächste Update behandelt werden, das bald erscheinen sollte.

@zhengbli Gibt es ein Update zu diesem Problem?

Übrigens habe ich eine aktualisierte Definition für 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[]
}

Gute Arbeit! Ich habe es ein wenig verbessert: Die Methode 'close' für die Notification-Klasse fehlte, und die Definition für die veraltete requestPermission-Methode war nicht ganz korrekt.

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[]
}

Wie beobachten Sie einen Aktionsklick?

@ mwent-cray StackOverflow ist der Ort für Fragen.

@marcovdb @mhegazy sind Benachrichtigungsdefinitionen noch in TS 2.4? Weil ich es dort nicht zu finden scheine: - |

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

@marcovdb Gibt es einen Grund, warum sich die Benutzeroberfläche von dem in Ihrem letzten Beitrag im Thread erwähnten Code unterscheidet?

Entschuldigung, keine Ahnung. Sie müssten die Person fragen, die die Definitionen tatsächlich beigesteuert hat. Das wäre @zhengbli.

@zhengbli warum wurden alle bis auf 5 der NotificationOptions weggelassen? 😞

@ialexryan Bitte

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen

Verwandte Themen

uber5001 picture uber5001  ·  3Kommentare

blendsdk picture blendsdk  ·  3Kommentare

dlaberge picture dlaberge  ·  3Kommentare

manekinekko picture manekinekko  ·  3Kommentare

jbondc picture jbondc  ·  3Kommentare