From 806ce0e7a7740e6fd330633e2d28795e33b8d95f Mon Sep 17 00:00:00 2001 From: Tobias Ortmayr Date: Tue, 19 Sep 2023 11:38:46 +0200 Subject: [PATCH] Fix typing of RequestActions Add an artificial property to the `RequestAction` definition to ensure that the generic type literal is not unused. This ensure that the TS compiler has all required type information and can implicitly derive the type of the Response action from a request action. Fixes https://github.com/eclipse-sprotty/sprotty/issues/378 --- packages/sprotty-protocol/src/actions.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/sprotty-protocol/src/actions.ts b/packages/sprotty-protocol/src/actions.ts index f41ade07..46c4be1e 100644 --- a/packages/sprotty-protocol/src/actions.ts +++ b/packages/sprotty-protocol/src/actions.ts @@ -50,6 +50,11 @@ export function isAction(object?: unknown): object is Action { */ export interface RequestAction extends Action { requestId: string + + /** + * Used to ensure correct typing. Clients must not use this property + */ + readonly _?: Res; } export function isRequestAction(object?: Action): object is RequestAction { @@ -607,7 +612,7 @@ export namespace ViewportResult { /** * Action to render the selected elements in front of others by manipulating the z-order. */ - export interface BringToFrontAction extends Action { +export interface BringToFrontAction extends Action { kind: typeof BringToFrontAction.KIND; elementIDs: string[] }