diff --git a/types/update-notifier/index.d.ts b/types/update-notifier/index.d.ts index 11f6e5616e..98c71d87f6 100644 --- a/types/update-notifier/index.d.ts +++ b/types/update-notifier/index.d.ts @@ -1,17 +1,21 @@ -// Type definitions for update-notifier 2.0 +// Type definitions for update-notifier 2.2 // Project: https://github.com/yeoman/update-notifier -// Definitions by: vvakame , Noah Chen +// Definitions by: vvakame +// Noah Chen +// Jason Dreyzehner // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped export = UpdateNotifier; -declare function UpdateNotifier(settings?: UpdateNotifier.Settings): UpdateNotifier.UpdateNotifier; +declare function UpdateNotifier( + settings?: UpdateNotifier.Settings +): UpdateNotifier.UpdateNotifier; declare namespace UpdateNotifier { class UpdateNotifier { constructor(settings?: Settings); - update: UpdateInfo; + update?: UpdateInfo; check(): void; checkNpm(): void; notify(customMessage?: NotifyOptions): void; @@ -19,7 +23,7 @@ declare namespace UpdateNotifier { interface Settings { pkg?: Package; - callback?(update?: UpdateInfo): any; + callback?(error: Error | null, update?: UpdateInfo): any; packageName?: string; packageVersion?: string; updateCheckInterval?: number; // in milliseconds, default 1000 * 60 * 60 * 24 (1 day) diff --git a/types/update-notifier/update-notifier-tests.ts b/types/update-notifier/update-notifier-tests.ts index fc55c3286a..c09fcf556a 100644 --- a/types/update-notifier/update-notifier-tests.ts +++ b/types/update-notifier/update-notifier-tests.ts @@ -1,16 +1,16 @@ -import UpdateNotifier = require("update-notifier"); +import UpdateNotifier = require('update-notifier'); let notifier = UpdateNotifier(); if (notifier.update) { - notifier.notify(); + notifier.notify(); } console.log(notifier.update); // Also exposed as a class notifier = new UpdateNotifier.UpdateNotifier({ - updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week + updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week }); if (notifier.update) { @@ -27,7 +27,22 @@ if (notifier.update) { margin: 1, align: 'center', borderColor: 'yellow', - borderStyle: 'round', - }, + borderStyle: 'round' + } }); } + +// Using the callback option +notifier = new UpdateNotifier.UpdateNotifier({ + callback: (err, update) => { + if (err) throw err; + if (update) { + console.log( + update.current, + update.latest, + update.name, + update.type + ); + } + } +});