Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create typescript definition file #61

Open
pdeva opened this issue Apr 8, 2014 · 7 comments
Open

create typescript definition file #61

pdeva opened this issue Apr 8, 2014 · 7 comments

Comments

@pdeva
Copy link

pdeva commented Apr 8, 2014

if you could contribute a typescript definition file to the definitely typed repo it would be very helpful.
https://github.com/borisyankov/DefinitelyTyped

@jmesnil
Copy link
Owner

jmesnil commented Apr 10, 2014

I'm not familiar with typescript definition but if you would be interested to contribute a patch, I'll review it.

@paulbakker
Copy link

I ran into the same issue and created a starting point for a definition. It's far from complete, but I'm not familiar enough with the API yet to complete it.

// Type definitions for stomp.js
// Custom type definition, not complete.

interface Stomp {
    over(socketType:any) : Client;
}

interface StompMessage {
    body : string;
}

interface HeartBeatConfig {
    incoming : number;
    outgoing : number;
}

interface Client {
    connect(user: string, password : string, onConnect: () => any, onError : () => any, path : string);
    subscribe(url : string, handler: (message : StompMessage) => any);
    heartbeat : HeartBeatConfig;
}

declare var Stomp : Stomp;

@dwasyluk
Copy link

dwasyluk commented Dec 4, 2015

It would be great to see this typedef fully completed. We're using SockJS in a current project, I'll use the base @paulbakker put together and try to complete it.

@atsu85
Copy link

atsu85 commented Jan 18, 2016

I came up with following TypeScript definition (more than enough for me):

/**
 * it is possible to use other type of WebSockets by using the Stomp.over(ws) method. This method expects an object that conforms to the WebSocket definition.
 * TODO specifi minimal required object structure, see SockJS as an acceptable example: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/sockjs/sockjs.d.ts#L23
 */
declare type StompMinimalWebSocketDefinition = /* SockJS | */ any ;
declare type StompWebSocketDefinition = WebSocket | StompMinimalWebSocketDefinition;

declare type StompHeaders = { [key: string ]: string;};
declare type StompSubscriptions = { [key: string ]: string;};
declare type StompFrameCallback = (frame: StompFrame) => void;

interface StompFrame {
  command: string;
  headers: StompHeaders;
  body?: string;
}

interface StompStatic {
  over(webSocket: StompWebSocketDefinition): StompClient;
}

interface StompSubscription {
  id: any;
  unsubscribe: () => void;
}

interface HeartBeatConfig {
    incoming : number;
    outgoing : number;
}

interface StompClient {
  /* START: object internals, maybe not for public use
  connectCallback: StompFrameCallback;
  connected: boolean;
  counter: number;
  maxWebSocketFrameSize: number;
  partialData: string;
  serverActivity: number;
  subscriptions: { [key: string ]: StompFrameCallback;};
  ws: StompMinimalWebSocketDefinition;
  */
  debug: (msg: string) => void;
  heartbeat : HeartBeatConfig;
  connect(login: string, passcode: string, connectCallback?: () => void, errorCallback?: () => void, host?: string);
  connect(headers: StompHeaders, connectCallback?: StompFrameCallback, errorCallback?: StompFrameCallback);
  subscribe(destination: string, callback: (stompFrame: StompFrame, headers?: StompHeaders) => void): StompSubscription;
  disconnect(disconnectCallback?: () => void);
}

declare var Stomp: StompStatic;

(I'll also add the link in case i'll update it later: https://gist.github.com/atsu85/346b8794bf5d8b27772c)

@atsu85
Copy link

atsu85 commented Jan 18, 2016

@jmesnil, Thanks for the effort with this project.
Could You take a look at the fields I've added and commented out from StompClient definition - what are the fields that are meant for internal use, and shouldn't be included in the TypeScript definitions?

I know You are not actively working on it right now, but i'd appreciate some feedback :)

@JimiC
Copy link

JimiC commented Nov 11, 2016

Typings for stompjs are now available at DefinitelyTyped types-2.0 branch.

@JimiC
Copy link

JimiC commented Nov 15, 2016

Type definitions are now available at @types/stompjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants