Skip to content

Commit 0c44feb

Browse files
authored
🤖 Merge PR DefinitelyTyped#72818 fix(node/diagnostics_channel): fix runStores() & trace*() signatures by @hkleungai
1 parent acf2c36 commit 0c44feb

File tree

6 files changed

+100
-82
lines changed

6 files changed

+100
-82
lines changed

‎types/node/diagnostics_channel.d.ts‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,12 @@ declare module "diagnostics_channel" {
297297
* @param thisArg The receiver to be used for the function call.
298298
* @param args Optional arguments to pass to the function.
299299
*/
300-
runStores(): void;
300+
runStores<ThisArg = any, Args extends any[] = any[], Result = any>(
301+
context: ContextType,
302+
fn: (this: ThisArg, ...args: Args) => Result,
303+
thisArg?: ThisArg,
304+
...args: Args
305+
): Result;
301306
}
302307
interface TracingChannelSubscribers<ContextType extends object> {
303308
start: (message: ContextType) => void;
@@ -441,12 +446,12 @@ declare module "diagnostics_channel" {
441446
* @param args Optional arguments to pass to the function
442447
* @return The return value of the given function
443448
*/
444-
traceSync<ThisArg = any, Args extends any[] = any[]>(
445-
fn: (this: ThisArg, ...args: Args) => any,
449+
traceSync<ThisArg = any, Args extends any[] = any[], Result = any>(
450+
fn: (this: ThisArg, ...args: Args) => Result,
446451
context?: ContextType,
447452
thisArg?: ThisArg,
448453
...args: Args
449-
): void;
454+
): Result;
450455
/**
451456
* Trace a promise-returning function call. This will always produce a `start event` and `end event` around the synchronous portion of the
452457
* function execution, and will produce an `asyncStart event` and `asyncEnd event` when a promise continuation is reached. It may also
@@ -476,12 +481,12 @@ declare module "diagnostics_channel" {
476481
* @param args Optional arguments to pass to the function
477482
* @return Chained from promise returned by the given function
478483
*/
479-
tracePromise<ThisArg = any, Args extends any[] = any[]>(
480-
fn: (this: ThisArg, ...args: Args) => Promise<any>,
484+
tracePromise<ThisArg = any, Args extends any[] = any[], Result = any>(
485+
fn: (this: ThisArg, ...args: Args) => Promise<Result>,
481486
context?: ContextType,
482487
thisArg?: ThisArg,
483488
...args: Args
484-
): void;
489+
): Promise<Result>;
485490
/**
486491
* Trace a callback-receiving function call. This will always produce a `start event` and `end event` around the synchronous portion of the
487492
* function execution, and will produce a `asyncStart event` and `asyncEnd event` around the callback execution. It may also produce an `error event` if the given function throws an error or
@@ -540,13 +545,13 @@ declare module "diagnostics_channel" {
540545
* @param args Optional arguments to pass to the function
541546
* @return The return value of the given function
542547
*/
543-
traceCallback<Fn extends (this: any, ...args: any[]) => any>(
544-
fn: Fn,
548+
traceCallback<ThisArg = any, Args extends any[] = any[], Result = any>(
549+
fn: (this: ThisArg, ...args: Args) => Result,
545550
position?: number,
546551
context?: ContextType,
547-
thisArg?: any,
548-
...args: Parameters<Fn>
549-
): void;
552+
thisArg?: ThisArg,
553+
...args: Args
554+
): Result;
550555
/**
551556
* `true` if any of the individual channels has a subscriber, `false` if not.
552557
*

‎types/node/test/diagnostics_channel.ts‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const hasSubs = hasSubscribers("test");
7979
const a: number = 1;
8080
const b: string = "2";
8181

82+
// $ExpectType string
8283
channels.traceSync(
8384
function(a, b) {
8485
this; // $ExpectType string
@@ -92,10 +93,12 @@ const hasSubs = hasSubscribers("test");
9293
b,
9394
);
9495

96+
// $ExpectType string
9597
channels.traceSync(function() {
9698
return "something";
9799
}, { requestId: 42 });
98100

101+
// $ExpectType Promise<string>
99102
channels.tracePromise(
100103
async function(a, b) {
101104
this; // $ExpectType string
@@ -109,34 +112,32 @@ const hasSubs = hasSubscribers("test");
109112
b,
110113
);
111114

115+
// $ExpectType Promise<string>
112116
channels.tracePromise(async function() {
113117
return "something";
114118
}, { requestId: 42 });
115119

116120
const callback = (err: unknown, result: string) => {};
117121

122+
// $ExpectType void
118123
channels.traceCallback(
119-
function(arg1, callback) {
124+
function(arg1, arg2, arg3, callback): void {
125+
// $ExpectType number
126+
arg1;
127+
// $ExpectType number
128+
arg2;
129+
// $ExpectType string
130+
arg3;
120131
callback(null, "result");
121132
},
122-
1,
133+
3,
123134
{
124135
requestId: 42,
125136
},
126137
"thisArg",
127138
42,
128-
callback,
129-
);
130-
131-
channels.traceCallback(
132-
function(callback) {
133-
callback(null, "result");
134-
},
135-
undefined,
136-
{
137-
requestId: 42,
138-
},
139-
undefined,
139+
1,
140+
"k",
140141
callback,
141142
);
142143

‎types/node/v18/diagnostics_channel.d.ts‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,12 @@ declare module "diagnostics_channel" {
298298
* @param thisArg The receiver to be used for the function call.
299299
* @param args Optional arguments to pass to the function.
300300
*/
301-
runStores(): void;
301+
runStores<ThisArg = any, Args extends any[] = any[], Result = any>(
302+
context: ContextType,
303+
fn: (this: ThisArg, ...args: Args) => Result,
304+
thisArg?: ThisArg,
305+
...args: Args
306+
): Result;
302307
}
303308
interface TracingChannelSubscribers<ContextType extends object> {
304309
start: (message: ContextType) => void;
@@ -439,12 +444,12 @@ declare module "diagnostics_channel" {
439444
* @param args Optional arguments to pass to the function
440445
* @return The return value of the given function
441446
*/
442-
traceSync<ThisArg = any, Args extends any[] = any[]>(
443-
fn: (this: ThisArg, ...args: Args) => any,
447+
traceSync<ThisArg = any, Args extends any[] = any[], Result = any>(
448+
fn: (this: ThisArg, ...args: Args) => Result,
444449
context?: ContextType,
445450
thisArg?: ThisArg,
446451
...args: Args
447-
): void;
452+
): Result;
448453
/**
449454
* Trace a promise-returning function call. This will always produce a `start event` and `end event` around the synchronous portion of the
450455
* function execution, and will produce an `asyncStart event` and `asyncEnd event` when a promise continuation is reached. It may also
@@ -471,12 +476,12 @@ declare module "diagnostics_channel" {
471476
* @param args Optional arguments to pass to the function
472477
* @return Chained from promise returned by the given function
473478
*/
474-
tracePromise<ThisArg = any, Args extends any[] = any[]>(
475-
fn: (this: ThisArg, ...args: Args) => Promise<any>,
479+
tracePromise<ThisArg = any, Args extends any[] = any[], Result = any>(
480+
fn: (this: ThisArg, ...args: Args) => Promise<Result>,
476481
context?: ContextType,
477482
thisArg?: ThisArg,
478483
...args: Args
479-
): void;
484+
): Promise<Result>;
480485
/**
481486
* Trace a callback-receiving function call. This will always produce a `start event` and `end event` around the synchronous portion of the
482487
* function execution, and will produce a `asyncStart event` and `asyncEnd event` around the callback execution. It may also produce an `error event` if the given function throws an error or
@@ -532,13 +537,13 @@ declare module "diagnostics_channel" {
532537
* @param args Optional arguments to pass to the function
533538
* @return The return value of the given function
534539
*/
535-
traceCallback<Fn extends (this: any, ...args: any) => any>(
536-
fn: Fn,
537-
position: number | undefined,
538-
context: ContextType | undefined,
539-
thisArg: any,
540-
...args: Parameters<Fn>
541-
): void;
540+
traceCallback<ThisArg = any, Args extends any[] = any[], Result = any>(
541+
fn: (this: ThisArg, ...args: Args) => Result,
542+
position?: number,
543+
context?: ContextType,
544+
thisArg?: ThisArg,
545+
...args: Args
546+
): Result;
542547
}
543548
}
544549
declare module "node:diagnostics_channel" {

‎types/node/v18/test/diagnostics_channel.ts‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const hasSubs = hasSubscribers("test");
7979
const a: number = 1;
8080
const b: string = "2";
8181

82+
// $ExpectType string
8283
channels.traceSync(
8384
function(a, b) {
8485
this; // $ExpectType string
@@ -92,10 +93,12 @@ const hasSubs = hasSubscribers("test");
9293
b,
9394
);
9495

96+
// $ExpectType string
9597
channels.traceSync(function() {
9698
return "something";
9799
}, { requestId: 42 });
98100

101+
// $ExpectType Promise<string>
99102
channels.tracePromise(
100103
async function(a, b) {
101104
this; // $ExpectType string
@@ -109,34 +112,32 @@ const hasSubs = hasSubscribers("test");
109112
b,
110113
);
111114

115+
// $ExpectType Promise<string>
112116
channels.tracePromise(async function() {
113117
return "something";
114118
}, { requestId: 42 });
115119

116120
const callback = (err: unknown, result: string) => {};
117121

122+
// $ExpectType void
118123
channels.traceCallback(
119-
function(arg1, callback) {
124+
function(arg1, arg2, arg3, callback): void {
125+
// $ExpectType number
126+
arg1;
127+
// $ExpectType number
128+
arg2;
129+
// $ExpectType string
130+
arg3;
120131
callback(null, "result");
121132
},
122-
1,
133+
3,
123134
{
124135
requestId: 42,
125136
},
126137
"thisArg",
127138
42,
128-
callback,
129-
);
130-
131-
channels.traceCallback(
132-
function(callback) {
133-
callback(null, "result");
134-
},
135-
undefined,
136-
{
137-
requestId: 42,
138-
},
139-
undefined,
139+
1,
140+
"k",
140141
callback,
141142
);
142143
}

‎types/node/v20/diagnostics_channel.d.ts‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,12 @@ declare module "diagnostics_channel" {
297297
* @param thisArg The receiver to be used for the function call.
298298
* @param args Optional arguments to pass to the function.
299299
*/
300-
runStores(): void;
300+
runStores<ThisArg = any, Args extends any[] = any[], Result = any>(
301+
context: ContextType,
302+
fn: (this: ThisArg, ...args: Args) => Result,
303+
thisArg?: ThisArg,
304+
...args: Args
305+
): Result;
301306
}
302307
interface TracingChannelSubscribers<ContextType extends object> {
303308
start: (message: ContextType) => void;
@@ -441,12 +446,12 @@ declare module "diagnostics_channel" {
441446
* @param args Optional arguments to pass to the function
442447
* @return The return value of the given function
443448
*/
444-
traceSync<ThisArg = any, Args extends any[] = any[]>(
445-
fn: (this: ThisArg, ...args: Args) => any,
449+
traceSync<ThisArg = any, Args extends any[] = any[], Result = any>(
450+
fn: (this: ThisArg, ...args: Args) => Result,
446451
context?: ContextType,
447452
thisArg?: ThisArg,
448453
...args: Args
449-
): void;
454+
): Result;
450455
/**
451456
* Trace a promise-returning function call. This will always produce a `start event` and `end event` around the synchronous portion of the
452457
* function execution, and will produce an `asyncStart event` and `asyncEnd event` when a promise continuation is reached. It may also
@@ -476,12 +481,12 @@ declare module "diagnostics_channel" {
476481
* @param args Optional arguments to pass to the function
477482
* @return Chained from promise returned by the given function
478483
*/
479-
tracePromise<ThisArg = any, Args extends any[] = any[]>(
480-
fn: (this: ThisArg, ...args: Args) => Promise<any>,
484+
tracePromise<ThisArg = any, Args extends any[] = any[], Result = any>(
485+
fn: (this: ThisArg, ...args: Args) => Promise<Result>,
481486
context?: ContextType,
482487
thisArg?: ThisArg,
483488
...args: Args
484-
): void;
489+
): Promise<Result>;
485490
/**
486491
* Trace a callback-receiving function call. This will always produce a `start event` and `end event` around the synchronous portion of the
487492
* function execution, and will produce a `asyncStart event` and `asyncEnd event` around the callback execution. It may also produce an `error event` if the given function throws an error or
@@ -540,13 +545,13 @@ declare module "diagnostics_channel" {
540545
* @param args Optional arguments to pass to the function
541546
* @return The return value of the given function
542547
*/
543-
traceCallback<Fn extends (this: any, ...args: any) => any>(
544-
fn: Fn,
545-
position: number | undefined,
546-
context: ContextType | undefined,
547-
thisArg: any,
548-
...args: Parameters<Fn>
549-
): void;
548+
traceCallback<ThisArg = any, Args extends any[] = any[], Result = any>(
549+
fn: (this: ThisArg, ...args: Args) => Result,
550+
position?: number,
551+
context?: ContextType,
552+
thisArg?: ThisArg,
553+
...args: Args
554+
): Result;
550555
/**
551556
* `true` if any of the individual channels has a subscriber, `false` if not.
552557
*

0 commit comments

Comments
 (0)