amqplib icon indicating copy to clipboard operation
amqplib copied to clipboard

Add typescript type definitions

Open nfantone opened this issue 9 years ago • 10 comments

@squaremo I don't know if you are really into this - but hey, here it is, nonetheless.

This PR would allow library/module writers to consume "official" type definitions for amqplib in their TS 2.0 projects (such as rx-amqplib) without hassle, by just installing the client from npm.

npm i amqplib
npm i --save-dev @types/bluebird @types/node

Additional "peerDependencies" are needed because the definitions file (index.d.ts) depends on external typings. Regular users won't need to install those and can safely ignore all this.

nfantone avatar Nov 02 '16 00:11 nfantone

This looks worthwhile. I am a little worried that it means people changing the JS code will need to also change the type definitions, or they will be out of date (i.e., it will require some expertise in TypeScript). Can you comment on that?

squaremo avatar Feb 08 '17 06:02 squaremo

@squaremo Well... the answer is: it depends. If changes on JS code update the API, TS definitions should be changed as well to reflect that. No way around that, I'm afraid.

it will require some expertise in TypeScript

Typescript is very easy to grasp if you are familiar with ES6+. And we are only interested in typings here. Just by looking at the only relevant file, index.d.ts, you can already get a feel of what's going on. No bones about it, really.

If this is a concern for you, people can always install those using typings via DefinitelyTyped repos. Microsoft is trying to move users away from that, though.

Your call.

nfantone avatar Feb 08 '17 18:02 nfantone

+1 This would add a lot of value to us TS users.

The "ideal" way proposed by the TS team is for projects to offer their own typings. This gives them more visibility and helps to keep them updated, since the typings would be "official".

The alternative is having them in the DefinitelyTyped repo (the url changed) and publishing them to @types/amqplib, installing them with npm i -D @types/ampqlib.

As @nfantone said, the typings would only need to be updated if the API changes.

lautarodragan avatar Nov 02 '17 19:11 lautarodragan

@squaremo What is the final decision on that, do we want it in? I can fix the conflict in this PR if it is OK in general.

kibertoad avatar Apr 28 '18 12:04 kibertoad

It has been over a year. Any progress on this?

MrManny avatar Jul 23 '19 11:07 MrManny

Having used TypeScript in another context, I have a better appreciation of why type definitions are useful. Can we check the types are correct in the CI build?

squaremo avatar Jul 26 '19 20:07 squaremo

@squaremo you can't check that the types match the implementation if the source code isn't written in TypeScript itself, but there are some basic tests that can be done.

Basically declaring stuff and seeing it pass the type checker.

Here's ReactJS type definitions tests, for example: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/v15/test/index.ts

lautarodragan avatar Jul 26 '19 22:07 lautarodragan

Any chance we can get this merged?

Recodify avatar Nov 30 '19 23:11 Recodify

@squaremo, @nfantone sorry, have this been abandoned? Do you need some help?

zernie avatar Jun 04 '20 09:06 zernie

There is @types/amqplib. This has worked for our purposes. But official support would be appreciated. I can also help out if needed.

daniel-pedersen avatar Jun 04 '20 10:06 daniel-pedersen