Skip to content
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

Closed
kk80805588 opened this issue May 11, 2015 · 19 comments
Closed

Please add Notification.requestPermission() #3111

kk80805588 opened this issue May 11, 2015 · 19 comments
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this Suggestion An idea for TypeScript

Comments

@kk80805588
Copy link

https://developer.mozilla.org/zh-CN/docs/Web/API/notification/Using_Web_Notifications
unf _n c9y b 1_n 3phz h

@RyanCavanaugh RyanCavanaugh added the By Design Deprecated - use "Working as Intended" or "Design Limitation" instead label May 11, 2015
@RyanCavanaugh
Copy link
Member

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.

@heruan
Copy link

heruan commented Jun 14, 2016

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 --lib option).

@kitsonk
Copy link
Contributor

kitsonk commented Jun 14, 2016

This was closed over 13 months ago, when Notification was from standard.

This can be addressed by contributing to the TS-Lib-Generator.

@heruan
Copy link

heruan commented Jun 14, 2016

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 addedTypes.json file (as the contribution guidelines state), since the interface has static/readonly properties not covered by the build script.

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

@mhegazy mhegazy reopened this Jun 14, 2016
@mhegazy mhegazy added Suggestion An idea for TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this and removed By Design Deprecated - use "Working as Intended" or "Design Limitation" instead labels Jun 14, 2016
@kitsonk
Copy link
Contributor

kitsonk commented Jun 14, 2016

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)?

@kitsonk
Copy link
Contributor

kitsonk commented Jun 14, 2016

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?

@zhengbli
Copy link
Contributor

zhengbli commented Jun 15, 2016

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, NotificationOptions is indeed available in the latest Edge build. It should be covered next update, which should be soon.

@mhegazy mhegazy modified the milestone: Community Sep 21, 2016
@FranklinWhale
Copy link

@zhengbli Is there any update on this issue?

@FranklinWhale
Copy link

By the way, I have made an updated defintion for 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[]
}

@marcovdb
Copy link

marcovdb commented Dec 27, 2016

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

@mhegazy
Copy link
Contributor

mhegazy commented Feb 1, 2017

@mhegazy mhegazy added the Fixed in TSJS repo Fix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet label Feb 1, 2017
@mhegazy mhegazy modified the milestones: TypeScript 2.2, Community Feb 1, 2017
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Feb 2, 2017
@zhengbli zhengbli removed the Fixed in TSJS repo Fix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet label Feb 3, 2017
@mwent-cray
Copy link

How do you watch for a action click?

@wonea
Copy link

wonea commented Jul 9, 2017

@mwent-cray StackOverflow is the place for questions.

@Shavindra
Copy link

Shavindra commented Aug 3, 2017

@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

@marcovdb
Copy link

marcovdb commented Aug 3, 2017

@Shavindra
Copy link

@marcovdb is there a reason why the interface is different from code mentioned in your last post in thread?

@marcovdb
Copy link

marcovdb commented Aug 3, 2017

Sorry, no idea. You'd have to ask the person that actually contributed the definitions. That would be @zhengbli.

@ialexryan
Copy link
Contributor

@zhengbli why were all but 5 of the NotificationOptions omitted? 😞

@mhegazy
Copy link
Contributor

mhegazy commented Nov 20, 2017

@ialexryan please file a new issue and give us some context about the issue, and i would be happy to look into it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests