Skip to content

Commit

Permalink
Merge pull request #15 from TypeFox/dh/type-checks
Browse files Browse the repository at this point in the history
Improve type checking for notification and request types
  • Loading branch information
dhuebner authored Dec 7, 2023
2 parents d6b861a + 6d39312 commit 3f12a81
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
19 changes: 15 additions & 4 deletions packages/vscode-messenger-common/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,14 @@ export type JsonArray = JsonAny[];
/**
* Data structure for defining a request type.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export type RequestType<P, R> = { method: string };
export type RequestType<P, R> = {
method: string

/**
* Used to ensure correct typing. Clients must not use this property
*/
readonly _?: [P,R]
};

/**
* Function for handling incoming requests.
Expand All @@ -153,8 +159,13 @@ export type HandlerResult<R> = R | Promise<R>;
/**
* Data structure for defining a notification type.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export type NotificationType<P> = { method: string };
export type NotificationType<P> = {
method: string
/**
* Used to ensure correct typing. Clients must not use this property
*/
readonly _?: P
};

/**
* Function for handling incoming notifications.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import ForceGraph2D, { ForceGraphMethods, GraphData, LinkObject, NodeObject } from 'react-force-graph-2d';

type GraphObjectExtension = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ describe('Webview Messenger', () => {
messenger1.start();
const messenger2 = new Messenger(vsCodeApi);
messenger2.start();
messenger1.sendRequest(stringNotification, HOST_EXTENSION, 'ping1');
messenger2.sendRequest(stringNotification, HOST_EXTENSION, 'ping2');
messenger1.sendRequest(stringRequest, HOST_EXTENSION, 'ping1');
messenger2.sendRequest(stringRequest, HOST_EXTENSION, 'ping2');

const message1 = vsCodeApi.messages[0] as unknown as any;
const message2 = vsCodeApi.messages[1] as unknown as any;
Expand Down

0 comments on commit 3f12a81

Please sign in to comment.