Skip to content

Commit

Permalink
Fix typing of RequestActions (#379)
Browse files Browse the repository at this point in the history
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 #378
  • Loading branch information
tortmayr authored Oct 5, 2023
1 parent 6488b8f commit 6e9cd10
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/sprotty-protocol/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export function isAction(object?: unknown): object is Action {
*/
export interface RequestAction<Res extends ResponseAction> 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<ResponseAction> {
Expand Down Expand Up @@ -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[]
}
Expand Down

0 comments on commit 6e9cd10

Please sign in to comment.