New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please add Notification.requestPermission() #3111
Comments
We try not to put non-standardized things in lib.d.ts. You can always include a .d.ts file yourself that includes definitions for these APIs. |
Isn't the Notification API actually a standard? https://notifications.spec.whatwg.org/ Since the Notification API is part of Web Workers, I'd expect to have it defined in one of the standard libs (e.g. with the new TS 1.9 |
This was closed over 13 months ago, when This can be addressed by contributing to the TS-Lib-Generator. |
Thank you @kitsonk I had a look to the TS-Lib-Generator to contribute but I couldn't guess the correct approach to add the Notification type in the This is the needed declaration: 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>;
} |
I am a little bit surprised that it hasn't come over yet, though I haven't looked at master. It is in Edge 14, so the IDLs for Edge should reflect that, which should generate it without overrides... I don't know enough, about the specifics, but do new APIs automagically appear when added to Edge's IDLs and what version of the IDLs are used when building (is it only released)? |
Ah, I see, the browser IDLs are currently 4 months old... which means it is likely they are "Edge 13" ones. @zhengbli how often/when do you update them? |
We used to take the Edge spec files along with official windows 10 releases, therefore the last update was the same as TH2. However, it makes more sense now to do a more frequent update to avoid wasted efforts from the community, we are taking to the Edge team trying to make a monthly update happen. Also, |
@zhengbli Is there any update on this issue? |
By the way, I have made an updated defintion for 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[]
} |
Great work! I improved it a bit: the 'close' method on the Notification class was missing, and the definition for the deprecated requestPermission method wasn't entirely correct. 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[]
} |
Should be added in the next release. See https://github.com/Microsoft/TSJS-lib-generator/blob/cd60588b72a9188e89346b3c440a76508b4c0e76/baselines/dom.generated.d.ts#L8360-L8381 |
How do you watch for a action click? |
@mwent-cray StackOverflow is the place for questions. |
@marcovdb @mhegazy is Notification definitions still in TS 2.4? Because I can't seem to find it there :-| https://github.com/Microsoft/TypeScript/blob/master/src/lib/dom.generated.d.ts |
Yes. It's in a different file. https://github.com/Microsoft/TypeScript/blob/master/src/lib/webworker.generated.d.ts |
@marcovdb is there a reason why the interface is different from code mentioned in your last post in thread? |
Sorry, no idea. You'd have to ask the person that actually contributed the definitions. That would be @zhengbli. |
@zhengbli why were all but 5 of the |
@ialexryan please file a new issue and give us some context about the issue, and i would be happy to look into it. |
https://developer.mozilla.org/zh-CN/docs/Web/API/notification/Using_Web_Notifications
The text was updated successfully, but these errors were encountered: