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 ํŒŒ์ผ์„ ์–ธ์ œ๋“ ์ง€ ์ง์ ‘ ํฌํ•จ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์•Œ๋ฆผ 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 ์ƒˆ ๋ฌธ์ œ๋ฅผ ์ œ์ถœํ•˜๊ณ  ๋ฌธ์ œ์— ๋Œ€ํ•œ ์ปจํ…์ŠคํŠธ๋ฅผ ์•Œ๋ ค ์ฃผ์‹œ๋ฉด ๊ธฐ๊บผ์ด ์กฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰