์ฐ๋ฆฌ๋ lib.d.ts์ ํ์คํ๋์ง ์์ ๊ฒ์ ๋ฃ์ง ์์ผ๋ ค ๊ณ ๋ ธ๋ ฅํฉ๋๋ค.
์ด๋ฌํ API์ ๋ํ ์ ์๊ฐ ํฌํจ ๋ .d.ts ํ์ผ์ ์ธ์ ๋ ์ง ์ง์ ํฌํจ ํ ์ ์์ต๋๋ค.
์๋ฆผ API๋ ์ค์ ๋ก ํ์ค์ด ์๋๋๊น? https://notifications.spec.whatwg.org/
์๋ฆผ API๋ Web Workers์ ์ผ๋ถ ์ด๋ฏ๋ก ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค ํ๋์ ์ ์ ํ ๊ฒ์ผ๋ก ์์ํฉ๋๋ค (์ : ์๋ก์ด TS 1.9 --lib
์ต์
์ฌ์ฉ).
์ด๊ฒ์ Notification
๊ฐ ํ์ค์์ ๋์จ 13 ๊ฐ์ ์ ์ ๋ง๊ฐ๋์์ต๋๋ค.
์ด๊ฒ์ TS-Lib-Generator ์
๋น์ ์ ๋ด๊ฐ ๊ธฐ์ฌํ๊ธฐ ์ํด TS-lib ๋๋ ํ ๋ฆฌ - ๋ฐ์ ๊ธฐ์๋ณด๊ณ ํ๋ค @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์ ์์ผ๋ฏ๋ก Edge์ IDL์์ด๋ฅผ ๋ฐ์ํด์ผํฉ๋๋ค. ์ด๋ ์ฌ์ ์์์ด ์์ฑํด์ผํฉ๋๋ค. ์ธ๋ถ ์ฌํญ์ ๋ํด์๋ ์ถฉ๋ถํ ๋ชจ๋ฅด์ง๋ง Edge์ IDL์ ์ถ๊ฐ๋๋ฉด ์๋ก์ด API๊ฐ ์๋์ผ๋ก ๋ํ๋ฉ๋๋ค. ๊ตฌ์ถ ํ ๋ IDL์ด ์ฌ์ฉ๋ฉ๋๊น (์ถ์ ๋ ๊ฒฝ์ฐ์๋ง)?
์, ์๊ฒ ์ต๋๋ค. ๋ธ๋ผ์ฐ์ IDL์ ํ์ฌ 4 ๊ฐ์์ด๋์์ต๋๋ค. ์ฆ, "Edge 13"์ผ ๊ฐ๋ฅ์ฑ์ด ๋์ต๋๋ค. @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[]
}
๋ค์ ๋ฆด๋ฆฌ์ค์ ์ถ๊ฐ๋์ด์ผํฉ๋๋ค. https://github.com/Microsoft/TSJS-lib-generator/blob/cd60588b72a9188e89346b3c440a76508b4c0e76/baselines/dom.generated.d.ts#L8360 -L8381 ์ฐธ์กฐ
์ก์ ํด๋ฆญ์ ์ด๋ป๊ฒ ์ฃผ์ํฉ๋๊น?
@ mwent-cray StackOverflow๋ ์ง๋ฌธ์์ํ ์ฅ์์ ๋๋ค.
@marcovdb @mhegazy ๋ ์ฌ์ ํ TS 2.4์์๋ ์๋ฆผ ์ ์์ ๋๊น? ๊ฑฐ๊ธฐ์์ ์ฐพ์ ์์๋ ๊ฒ ๊ฐ์์ :-|
https://github.com/Microsoft/TypeScript/blob/master/src/lib/dom.generated.d.ts
์. ๋ค๋ฅธ ํ์ผ์ ์์ต๋๋ค.
https://github.com/Microsoft/TypeScript/blob/master/src/lib/webworker.generated.d.ts
@marcovdb ์ธํฐํ์ด์ค๊ฐ ์ค๋ ๋์ ๋ง์ง๋ง ๊ฒ์๋ฌผ์์ ์ธ๊ธ ํ ์ฝ๋์ ๋ค๋ฅธ ์ด์ ๊ฐ ์์ต๋๊น?
์ฃ์กํฉ๋๋ค. ์ค์ ๋ก ์ ์์ ๊ธฐ์ฌํ ์ฌ๋์๊ฒ ๋ฌผ์ด๋ด์ผํฉ๋๋ค. @zhengbli์ ๋๋ค.
@zhengbli NotificationOptions
์ค 5 ๊ฐ๋ฅผ ์ ์ธํ๊ณ ๋ชจ๋ ์๋ต ๋ ์ด์ ๋ ๋ฌด์์
๋๊น? ๐
@ialexryan ์ ๋ฌธ์ ๋ฅผ ์ ์ถํ๊ณ ๋ฌธ์ ์ ๋ํ ์ปจํ ์คํธ๋ฅผ ์๋ ค ์ฃผ์๋ฉด ๊ธฐ๊บผ์ด ์กฐ์ฌํ๊ฒ ์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๊ทธ๊ฑด ๊ทธ๋ ๊ณ ,
Notification
๋ํ ์ ์๋ฅผ ์ ๋ฐ์ดํธํ์ต๋๋ค.