From 98a5d96dad224d595f8aea21e050f31fb2bad145 Mon Sep 17 00:00:00 2001 From: "Jimi (Dimitris) Charalampidis" Date: Wed, 9 May 2018 21:24:55 +0300 Subject: [PATCH] Improve types (#25654) --- types/stompjs/index.d.ts | 22 +++++++++++----------- types/stompjs/stompjs-tests.ts | 7 ++++--- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/types/stompjs/index.d.ts b/types/stompjs/index.d.ts index d78fa1b5d9..4c591367dc 100644 --- a/types/stompjs/index.d.ts +++ b/types/stompjs/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for stompjs 2.3 // Project: https://github.com/jmesnil/stomp-websocket -// Definitions by: Jimi Charalampidis , Stefan Erichsen +// Definitions by: Jimi Charalampidis +// Stefan Erichsen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -9,7 +10,7 @@ export const VERSIONS: { V1_0: string, V1_1: string, V1_2: string, - supportedVersions: () => Array + supportedVersions: () => string[] }; export class Client { @@ -31,8 +32,8 @@ export class Client { disconnect(disconnectCallback: () => any, headers?: {}): any; send(destination: string, headers?: {}, body?: string): any; - subscribe(destination: string, callback?: (message: Message) => any, headers?: {}): any; - unsubscribe(id: string): any; + subscribe(destination: string, callback?: (message: Message) => any, headers?: {}): Subscription; + unsubscribe(id: string): void; begin(transaction: string): any; commit(transaction: string): any; @@ -42,23 +43,22 @@ export class Client { nack(messageID: string, subscription: string, headers?: {}): any; } -export interface Message { - command: string; - headers: {}; - body: string; +export interface Subscription { + id: string; + unsubscribe(): void; +} +export interface Message extends Frame { ack(headers?: {}): any; nack(headers?: {}): any; } -export class Frame implements Message { +export class Frame { command: string; headers: {}; body: string; constructor(command: string, headers?: {}, body?: string); - ack(headers?: {}): any; - nack(headers?: {}): any; toString(): string; static sizeOfUTF8(s: string): number; static unmarshall(datas: any): any; diff --git a/types/stompjs/stompjs-tests.ts b/types/stompjs/stompjs-tests.ts index d7d5e45fde..9a3841e41a 100644 --- a/types/stompjs/stompjs-tests.ts +++ b/types/stompjs/stompjs-tests.ts @@ -61,10 +61,11 @@ client.send('destination'); client.send('destination', {}); client.send('destination', {}, 'body'); -client.subscribe('destination', (message) => { }); -client.subscribe('destination', (message) => { }, {}); +let subscription = client.subscribe('destination', (message) => { }); +subscription = client.subscribe('destination', (message) => { }, {}); +subscription.unsubscribe(); -client.unsubscribe('id'); +client.unsubscribe(subscription.id); client.begin('transaction');