Skip to content

Commit 5f0a99e

Browse files
committed
declare types for chrome-trace-event
1 parent 3677e25 commit 5f0a99e

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

declarations.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@ declare namespace NodeJS {
88
}
99
}
1010

11+
// There are no typings for chrome-trace-event
12+
declare module 'chrome-trace-event' {
13+
interface Event {
14+
name: string
15+
id?: number
16+
cat: string[]
17+
args?: Object
18+
}
19+
20+
export class Tracer {
21+
constructor(options: {
22+
noStream: boolean
23+
})
24+
pipe(stream: NodeJS.WritableStream) : void
25+
instantEvent(event: Event) : void
26+
counter: number
27+
trace: {
28+
begin(event: Event) : void
29+
end(event: Event) : void
30+
}
31+
}
32+
}
33+
1134
/**
1235
* Global variable declarations
1336
* @todo Once this issue is resolved, remove these globals and add JSDoc onsite instead

lib/debug/ProfilingPlugin.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,10 @@ const makeInterceptorFor = (instance, tracer) => hookName => ({
324324

325325
/**
326326
* @param {string} hookName Name of the hook to profile.
327-
* @param {{counter: number, trace: *, profiler: *}} tracer Instance of tracer.
327+
* @param {Tracer} tracer Instance of tracer.
328328
* @param {object} options Options for the profiled fn.
329-
* @param {string=} options.name Plugin name
330-
* @param {string=} options.type Plugin type (sync | async | promise)
329+
* @param {string} options.name Plugin name
330+
* @param {string} options.type Plugin type (sync | async | promise)
331331
* @param {PluginFunction} options.fn Plugin function
332332
* @returns {*} Chainable hooked function.
333333
*/
@@ -344,7 +344,8 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
344344
id,
345345
cat: defaultCategory
346346
});
347-
return fn(...args).then(r => {
347+
const promise = /** @type {Promise<*>} */ (fn(...args));
348+
return promise.then(r => {
348349
tracer.trace.end({
349350
name,
350351
id,

0 commit comments

Comments
 (0)