Skip to content

Commit c1829d3

Browse files
authored
chore: refine IClassicCom types (#3722)
* chore: refine comm types
1 parent 785d159 commit c1829d3

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

packages/base/src/services-shim.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import { Kernel, KernelMessage } from '@jupyterlab/services';
11+
import type { JSONValue, JSONObject } from '@lumino/coreutils';
1112

1213
/**
1314
* Callbacks for services shim comms.
@@ -40,9 +41,9 @@ export interface IClassicComm {
4041
* @return msg id
4142
*/
4243
open(
43-
data: any,
44-
callbacks: any,
45-
metadata?: any,
44+
data: JSONValue,
45+
callbacks?: ICallbacks,
46+
metadata?: JSONObject,
4647
buffers?: ArrayBuffer[] | ArrayBufferView[]
4748
): string;
4849

@@ -55,9 +56,9 @@ export interface IClassicComm {
5556
* @return message id
5657
*/
5758
send(
58-
data: any,
59-
callbacks: any,
60-
metadata?: any,
59+
data: JSONValue,
60+
callbacks?: ICallbacks,
61+
metadata?: JSONObject,
6162
buffers?: ArrayBuffer[] | ArrayBufferView[]
6263
): string;
6364

@@ -70,9 +71,9 @@ export interface IClassicComm {
7071
* @return msg id
7172
*/
7273
close(
73-
data?: any,
74-
callbacks?: any,
75-
metadata?: any,
74+
data?: JSONValue,
75+
callbacks?: ICallbacks,
76+
metadata?: JSONObject,
7677
buffers?: ArrayBuffer[] | ArrayBufferView[]
7778
): string;
7879

@@ -218,9 +219,9 @@ export namespace shims {
218219
* @return msg id
219220
*/
220221
open(
221-
data: any,
222-
callbacks: any,
223-
metadata?: any,
222+
data: JSONValue,
223+
callbacks?: ICallbacks,
224+
metadata?: JSONObject,
224225
buffers?: ArrayBuffer[] | ArrayBufferView[]
225226
): string {
226227
const future = this.jsServicesComm.open(data, metadata, buffers);
@@ -237,9 +238,9 @@ export namespace shims {
237238
* @return message id
238239
*/
239240
send(
240-
data: any,
241-
callbacks: any,
242-
metadata?: any,
241+
data: JSONValue,
242+
callbacks?: ICallbacks,
243+
metadata?: JSONObject,
243244
buffers?: ArrayBuffer[] | ArrayBufferView[]
244245
): string {
245246
const future = this.jsServicesComm.send(data, metadata, buffers);
@@ -255,9 +256,9 @@ export namespace shims {
255256
* @return msg id
256257
*/
257258
close(
258-
data?: any,
259-
callbacks?: any,
260-
metadata?: any,
259+
data?: JSONValue,
260+
callbacks?: ICallbacks,
261+
metadata?: JSONObject,
261262
buffers?: ArrayBuffer[] | ArrayBufferView[]
262263
): string {
263264
const future = this.jsServicesComm.close(data, metadata, buffers);
@@ -288,7 +289,7 @@ export namespace shims {
288289
*/
289290
_hookupCallbacks(
290291
future: Kernel.IShellFuture,
291-
callbacks: ICallbacks
292+
callbacks?: ICallbacks
292293
): void {
293294
if (callbacks) {
294295
future.onReply = function (msg): void {

packages/base/src/widget.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import $ from 'jquery';
99

1010
import { NativeView } from './nativeview';
1111

12-
import { JSONObject } from '@lumino/coreutils';
12+
import { JSONObject, JSONValue } from '@lumino/coreutils';
1313

1414
import { Message, MessageLoop } from '@lumino/messaging';
1515

@@ -164,8 +164,8 @@ export class WidgetModel extends Backbone.Model {
164164
* Send a custom msg over the comm.
165165
*/
166166
send(
167-
content: {},
168-
callbacks: {},
167+
content: JSONValue,
168+
callbacks?: ICallbacks,
169169
buffers?: ArrayBuffer[] | ArrayBufferView[]
170170
): void {
171171
if (this.comm !== undefined) {

packages/controls/test/src/utils.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as widgets from '@jupyter-widgets/base';
55
import * as services from '@jupyterlab/services';
66
import { DummyManager } from './dummy-manager';
77

8+
import type { JSONValue, JSONObject } from '@lumino/coreutils';
9+
810
let numComms = 0;
911

1012
export class MockComm implements widgets.IClassicComm {
@@ -30,8 +32,9 @@ export class MockComm implements widgets.IClassicComm {
3032
}
3133

3234
open(
33-
data?: any,
34-
metadata?: any,
35+
data: JSONValue,
36+
callbacks?: widgets.ICallbacks,
37+
metadata?: JSONObject,
3538
buffers?: ArrayBuffer[] | ArrayBufferView[]
3639
): string {
3740
if (this._on_open) {
@@ -41,8 +44,9 @@ export class MockComm implements widgets.IClassicComm {
4144
}
4245

4346
close(
44-
data?: any,
45-
metadata?: any,
47+
data?: JSONValue,
48+
callbacks?: widgets.ICallbacks,
49+
metadata?: JSONObject,
4650
buffers?: ArrayBuffer[] | ArrayBufferView[]
4751
): string {
4852
if (this._on_close) {
@@ -52,8 +56,9 @@ export class MockComm implements widgets.IClassicComm {
5256
}
5357

5458
send(
55-
data?: any,
56-
metadata?: any,
59+
data: JSONValue,
60+
callbacks?: widgets.ICallbacks,
61+
metadata?: JSONObject,
5762
buffers?: ArrayBuffer[] | ArrayBufferView[]
5863
): string {
5964
return '';

0 commit comments

Comments
 (0)