mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-08 09:17:06 +08:00
update-notifier: correct signature of callback param, mark update as optional
This commit is contained in:
14
types/update-notifier/index.d.ts
vendored
14
types/update-notifier/index.d.ts
vendored
@@ -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)
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user