update-notifier: correct signature of callback param, mark update as optional

This commit is contained in:
Jason Dreyzehner
2018-03-05 23:38:21 -05:00
parent fbba9f55be
commit eb0e9edf12
2 changed files with 29 additions and 10 deletions

View File

@@ -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 <https://github.com/vvakame>, Noah Chen <https://github.com/nchen63>
// Definitions by: vvakame <https://github.com/vvakame>
// Noah Chen <https://github.com/nchen63>
// Jason Dreyzehner <https://github.com/bitjson>
// 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)

View File

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