Skip to content

Commit c116df7

Browse files
rohit-gohritargos
authored andcommitted
typings: add JSDoc typings for util
PR-URL: #38213 Refs: #38182 Refs: https://twitter.com/bradleymeck/status/1380643627211354115 Reviewed-By: Bradley Farias <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 89fe999 commit c116df7

File tree

1 file changed

+88
-4
lines changed

1 file changed

+88
-4
lines changed

lib/util.js

+88-4
Original file line numberDiff line numberDiff line change
@@ -65,59 +65,119 @@ const {
6565

6666
let internalDeepEqual;
6767

68+
/**
69+
* @deprecated since v4.0.0
70+
* @param {any} arg
71+
* @returns {arg is boolean}
72+
*/
6873
function isBoolean(arg) {
6974
return typeof arg === 'boolean';
7075
}
7176

77+
/**
78+
* @deprecated since v4.0.0
79+
* @param {any} arg
80+
* @returns {arg is null}
81+
*/
7282
function isNull(arg) {
7383
return arg === null;
7484
}
7585

86+
/**
87+
* @deprecated since v4.0.0
88+
* @param {any} arg
89+
* @returns {arg is (null | undefined)}
90+
*/
7691
function isNullOrUndefined(arg) {
7792
return arg === null || arg === undefined;
7893
}
7994

95+
/**
96+
* @deprecated since v4.0.0
97+
* @param {any} arg
98+
* @returns {arg is number}
99+
*/
80100
function isNumber(arg) {
81101
return typeof arg === 'number';
82102
}
83103

104+
/**
105+
* @param {any} arg
106+
* @returns {arg is string}
107+
*/
84108
function isString(arg) {
85109
return typeof arg === 'string';
86110
}
87111

112+
/**
113+
* @deprecated since v4.0.0
114+
* @param {any} arg
115+
* @returns {arg is symbol}
116+
*/
88117
function isSymbol(arg) {
89118
return typeof arg === 'symbol';
90119
}
91120

121+
/**
122+
* @deprecated since v4.0.0
123+
* @param {any} arg
124+
* @returns {arg is undefined}
125+
*/
92126
function isUndefined(arg) {
93127
return arg === undefined;
94128
}
95129

130+
/**
131+
* @deprecated since v4.0.0
132+
* @param {any} arg
133+
* @returns {a is NonNullable<object>}
134+
*/
96135
function isObject(arg) {
97136
return arg !== null && typeof arg === 'object';
98137
}
99138

139+
/**
140+
* @deprecated since v4.0.0
141+
* @param {any} e
142+
* @returns {arg is Error}
143+
*/
100144
function isError(e) {
101145
return ObjectPrototypeToString(e) === '[object Error]' || e instanceof Error;
102146
}
103147

148+
/**
149+
* @deprecated since v4.0.0
150+
* @param {any} arg
151+
* @returns {arg is Function}
152+
*/
104153
function isFunction(arg) {
105154
return typeof arg === 'function';
106155
}
107156

157+
/**
158+
* @deprecated since v4.0.0
159+
* @param {any} arg
160+
* @returns {arg is (boolean | null | number | string | symbol | undefined)}
161+
*/
108162
function isPrimitive(arg) {
109163
return arg === null ||
110164
(typeof arg !== 'object' && typeof arg !== 'function');
111165
}
112166

167+
/**
168+
* @param {number} n
169+
* @returns {string}
170+
*/
113171
function pad(n) {
114172
return n.toString().padStart(2, '0');
115173
}
116174

117175
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
118176
'Oct', 'Nov', 'Dec'];
119177

120-
// 26 Feb 16:19:34
178+
/**
179+
* @returns {string} 26 Feb 16:19:34
180+
*/
121181
function timestamp() {
122182
const d = new Date();
123183
const time = [pad(d.getHours()),
@@ -127,7 +187,11 @@ function timestamp() {
127187
}
128188

129189
let console;
130-
// Log is just a thin wrapper to console.log that prepends a timestamp
190+
/**
191+
* Log is just a thin wrapper to console.log that prepends a timestamp
192+
* @deprecated since v6.0.0
193+
* @type {(...args: any[]) => void}
194+
*/
131195
function log(...args) {
132196
if (!console) {
133197
console = require('internal/console/global');
@@ -144,9 +208,9 @@ function log(...args) {
144208
* functions as prototype setup using normal JavaScript does not work as
145209
* expected during bootstrapping (see mirror.js in r114903).
146210
*
147-
* @param {function} ctor Constructor function which needs to inherit the
211+
* @param {Function} ctor Constructor function which needs to inherit the
148212
* prototype.
149-
* @param {function} superCtor Constructor function to inherit prototype from.
213+
* @param {Function} superCtor Constructor function to inherit prototype from.
150214
* @throws {TypeError} Will error if either constructor is null, or if
151215
* the super constructor lacks a prototype.
152216
*/
@@ -170,6 +234,14 @@ function inherits(ctor, superCtor) {
170234
ObjectSetPrototypeOf(ctor.prototype, superCtor.prototype);
171235
}
172236

237+
/**
238+
* @deprecated since v6.0.0
239+
* @template T
240+
* @template S
241+
* @param {T} target
242+
* @param {S} source
243+
* @returns {S extends null ? T : (T & S)}
244+
*/
173245
function _extend(target, source) {
174246
// Don't do anything if source isn't an object
175247
if (source === null || typeof source !== 'object') return target;
@@ -193,6 +265,14 @@ const callbackifyOnRejected = hideStackFrames((reason, cb) => {
193265
return cb(reason);
194266
});
195267

268+
/**
269+
* @template {(...args: any[]) => Promise<any>} T
270+
* @param {T} original
271+
* @returns {T extends (...args: infer TArgs) => Promise<infer TReturn> ?
272+
* ((...params: [...TArgs, ((err: Error, ret: TReturn) => any)]) => void) :
273+
* never
274+
* }
275+
*/
196276
function callbackify(original) {
197277
if (typeof original !== 'function') {
198278
throw new ERR_INVALID_ARG_TYPE('original', 'Function', original);
@@ -227,6 +307,10 @@ function callbackify(original) {
227307
return callbackified;
228308
}
229309

310+
/**
311+
* @param {number} err
312+
* @returns {string}
313+
*/
230314
function getSystemErrorName(err) {
231315
validateNumber(err, 'err');
232316
if (err >= 0 || !NumberIsSafeInteger(err)) {

0 commit comments

Comments
 (0)