Skip to content

Commit e389e86

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 09cacd7 commit e389e86

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
@@ -74,59 +74,119 @@ const {
7474

7575
let internalDeepEqual;
7676

77+
/**
78+
* @deprecated since v4.0.0
79+
* @param {any} arg
80+
* @returns {arg is boolean}
81+
*/
7782
function isBoolean(arg) {
7883
return typeof arg === 'boolean';
7984
}
8085

86+
/**
87+
* @deprecated since v4.0.0
88+
* @param {any} arg
89+
* @returns {arg is null}
90+
*/
8191
function isNull(arg) {
8292
return arg === null;
8393
}
8494

95+
/**
96+
* @deprecated since v4.0.0
97+
* @param {any} arg
98+
* @returns {arg is (null | undefined)}
99+
*/
85100
function isNullOrUndefined(arg) {
86101
return arg === null || arg === undefined;
87102
}
88103

104+
/**
105+
* @deprecated since v4.0.0
106+
* @param {any} arg
107+
* @returns {arg is number}
108+
*/
89109
function isNumber(arg) {
90110
return typeof arg === 'number';
91111
}
92112

113+
/**
114+
* @param {any} arg
115+
* @returns {arg is string}
116+
*/
93117
function isString(arg) {
94118
return typeof arg === 'string';
95119
}
96120

121+
/**
122+
* @deprecated since v4.0.0
123+
* @param {any} arg
124+
* @returns {arg is symbol}
125+
*/
97126
function isSymbol(arg) {
98127
return typeof arg === 'symbol';
99128
}
100129

130+
/**
131+
* @deprecated since v4.0.0
132+
* @param {any} arg
133+
* @returns {arg is undefined}
134+
*/
101135
function isUndefined(arg) {
102136
return arg === undefined;
103137
}
104138

139+
/**
140+
* @deprecated since v4.0.0
141+
* @param {any} arg
142+
* @returns {a is NonNullable<object>}
143+
*/
105144
function isObject(arg) {
106145
return arg !== null && typeof arg === 'object';
107146
}
108147

148+
/**
149+
* @deprecated since v4.0.0
150+
* @param {any} e
151+
* @returns {arg is Error}
152+
*/
109153
function isError(e) {
110154
return ObjectPrototypeToString(e) === '[object Error]' || e instanceof Error;
111155
}
112156

157+
/**
158+
* @deprecated since v4.0.0
159+
* @param {any} arg
160+
* @returns {arg is Function}
161+
*/
113162
function isFunction(arg) {
114163
return typeof arg === 'function';
115164
}
116165

166+
/**
167+
* @deprecated since v4.0.0
168+
* @param {any} arg
169+
* @returns {arg is (boolean | null | number | string | symbol | undefined)}
170+
*/
117171
function isPrimitive(arg) {
118172
return arg === null ||
119173
(typeof arg !== 'object' && typeof arg !== 'function');
120174
}
121175

176+
/**
177+
* @param {number} n
178+
* @returns {string}
179+
*/
122180
function pad(n) {
123181
return StringPrototypePadStart(n.toString(), 2, '0');
124182
}
125183

126184
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
127185
'Oct', 'Nov', 'Dec'];
128186

129-
// 26 Feb 16:19:34
187+
/**
188+
* @returns {string} 26 Feb 16:19:34
189+
*/
130190
function timestamp() {
131191
const d = new Date();
132192
const t = ArrayPrototypeJoin([
@@ -138,7 +198,11 @@ function timestamp() {
138198
}
139199

140200
let console;
141-
// Log is just a thin wrapper to console.log that prepends a timestamp
201+
/**
202+
* Log is just a thin wrapper to console.log that prepends a timestamp
203+
* @deprecated since v6.0.0
204+
* @type {(...args: any[]) => void}
205+
*/
142206
function log(...args) {
143207
if (!console) {
144208
console = require('internal/console/global');
@@ -155,9 +219,9 @@ function log(...args) {
155219
* functions as prototype setup using normal JavaScript does not work as
156220
* expected during bootstrapping (see mirror.js in r114903).
157221
*
158-
* @param {function} ctor Constructor function which needs to inherit the
222+
* @param {Function} ctor Constructor function which needs to inherit the
159223
* prototype.
160-
* @param {function} superCtor Constructor function to inherit prototype from.
224+
* @param {Function} superCtor Constructor function to inherit prototype from.
161225
* @throws {TypeError} Will error if either constructor is null, or if
162226
* the super constructor lacks a prototype.
163227
*/
@@ -181,6 +245,14 @@ function inherits(ctor, superCtor) {
181245
ObjectSetPrototypeOf(ctor.prototype, superCtor.prototype);
182246
}
183247

248+
/**
249+
* @deprecated since v6.0.0
250+
* @template T
251+
* @template S
252+
* @param {T} target
253+
* @param {S} source
254+
* @returns {S extends null ? T : (T & S)}
255+
*/
184256
function _extend(target, source) {
185257
// Don't do anything if source isn't an object
186258
if (source === null || typeof source !== 'object') return target;
@@ -204,6 +276,14 @@ const callbackifyOnRejected = hideStackFrames((reason, cb) => {
204276
return cb(reason);
205277
});
206278

279+
/**
280+
* @template {(...args: any[]) => Promise<any>} T
281+
* @param {T} original
282+
* @returns {T extends (...args: infer TArgs) => Promise<infer TReturn> ?
283+
* ((...params: [...TArgs, ((err: Error, ret: TReturn) => any)]) => void) :
284+
* never
285+
* }
286+
*/
207287
function callbackify(original) {
208288
if (typeof original !== 'function') {
209289
throw new ERR_INVALID_ARG_TYPE('original', 'Function', original);
@@ -238,6 +318,10 @@ function callbackify(original) {
238318
return callbackified;
239319
}
240320

321+
/**
322+
* @param {number} err
323+
* @returns {string}
324+
*/
241325
function getSystemErrorName(err) {
242326
validateNumber(err, 'err');
243327
if (err >= 0 || !NumberIsSafeInteger(err)) {

0 commit comments

Comments
 (0)