nknorg/nkn-sdk-js

TypeScript declarations

Closed this issue · 3 comments

This SDK is lacking TypeScript declarations, which makes developing a TypeScript project using strict mode that uses this library a pain. There's no autocomplete, no intellisense, not to mention all kinds of errors and warnings all over the place.

I am building an app for the GR11 hackathon (Codeshare App using NKN), and was facing this exact issue. I decided to create my own declarations for the SDK library to get past the problem. I would like to share it so other people using this SDK can take advantage as well.

There are 2 ways to publish the declarations - either by adding them to the library itself, or by publishing them via the DefinitelyTyped project (which would create a new NPM package in the @types scope). Which one would you prefer?

I've shared the declarations file I've created in a gist for now. This is the formulation I'm using for it in my project right now (declared as a module); for publishing it would need to be slightly modified.

Let me know how you'd like me to proceed. I can turn it into a library and publish on Definitely Typed myself, or I could create a PR in this repository to have it attached to the library itself. Or you could take it from here and publish it yourself.

This would be really helpful.

Correct me if I'm wrong: create a PR in this repo should be the most developer friendly way, is that correct? If so, I would prefer a PR in this repo.

@yilunzhang You're correct, having types be part of the library itself is probably most convenient for the users of the library, although having a separate package in DefinitelyTyped is also a very common way to approach this and only adds the inconvenience of installing the types package. The added bonus of having type declarations as part of the library is that they can be updated alongside any updates to the code.

I will create the PR when I get the chance.

#74 merged