JSteunou / webstomp-client

Stomp client over websocket for browsers
Apache License 2.0
299 stars 59 forks source link

Typescript definition file #7

Closed cexbrayat closed 7 years ago

cexbrayat commented 8 years ago

First of all, thank you very much for the energy you're putting in the project.

I am, as a lot of Angular 2 developers, working more and more with TypeScript. And, as you may know, TypeScript needs typings for external librairies. So it would be great if you could add the typings to the DefinitelyTyped repository, or better, within the NPM module (as recent TypeScript compilers can pick it up automatically).

This is not a new issue, as you can see on the original repo https://github.com/jmesnil/stomp-websocket/issues/61

I'm not a TypeScript expert, but I slightly modified one of the propositions to have the bare minimum for my case (I don't know enough the library to make something more exhaustive).

declare module 'webstomp-client' {

  interface webstomp {
    over(socketType: any) : webstomp;
    connect(headers: any, connectCallback: () => any);
    subscribe(destination: string, callback: (message: StompMessage) => any);
  }

  interface StompMessage {
    body : string;
  }

  var webstomp: webstomp;
  export = webstomp;

}
JSteunou commented 8 years ago

I am sorry I do not know enough about Typescript. Does this mean that you cannot use this library without types definition?

cexbrayat commented 8 years ago

You can use it, but the compiler will complain (or won't even compile depending on your settings). If the fork gain in popularity, we can expect a few people with the same need.

The ideal would be to embed a webstomp-client.d.ts file in the dist directory of the NPM module (see http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html for more info). This file would contain roughly what I proposed (until a better TypeScript developer than me offers something better), although it lacks a few useful methods (like unsubscribe and others you'll think about).

With this, the TypeScript compiler should be happy.

JSteunou commented 8 years ago

I will think about it. On one hand I want to provide what's needed for this library, on the other hand I cannot spread efforts to please everyone using a JavaScript like language with specific files to add and mostly to maintain. What's the worst? Compiler with warning, or compiler with error because the .ts is not up to date?

cexbrayat commented 8 years ago

I completely understand, take your time. I think it would be a great help for TS developers who will have to find this file, but I understand your reluctance to maintain it.

mishtt commented 8 years ago

I am kind of stuck in the same boat - I need the typings so that I can use it in my current project. I have not found a work around 3 days into working with the library. it would be wonderful to have it but I would understand if its not a priority.

JSteunou commented 8 years ago

I see. Could it work for you guys with https://github.com/DefinitelyTyped/DefinitelyTyped ? If you guys can handle this .ts for your need by yourself it would help me a lot as I know nothing about TypeScript.

mishtt commented 8 years ago

Yes that would work - the ideal would be what @cexbrayat mentioned but yes if we could get something in DT then that would go a long way. I work for a major airline and we are in the process of adopting libraries for our core boiler plate project which will serve as a starter project for all new UI projects. I can help out if need be to maintain the definitions

sinedsem commented 8 years ago

That's so sad this issue is in "open" state... I am starting a new project, and I really need typings for this library. Any solutions right now?

JSteunou commented 8 years ago

I could take a PR but I am afraid I could not maintain the file when the lib will evolve. I need someone to take this in charge.

Le 8 août 2016 21:43, "sinedsem" notifications@github.com a écrit :

That's so sad this issue is in "open" state... I am starting a new project, and I really need typings for this library. Any solutions right now?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JSteunou/webstomp-client/issues/7#issuecomment-238352714, or mute the thread https://github.com/notifications/unsubscribe-auth/ACNyt44GoknzTx71Jg3C6NUNETVV__Zgks5qd4bCgaJpZM4IO6TH .

sinedsem commented 8 years ago

I am a newbie in frontend, that's why I need this out of the box. I don't understand yet how this works, so I completely agree: we need somebody in charge.

JimiC commented 7 years ago

Typings for stompjsare now available at DefinitelyTyped types-2.0 branch.