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

Typescript definitions missing #714

Open
v3rbalgit opened this issue Mar 4, 2019 · 9 comments
Open

Typescript definitions missing #714

v3rbalgit opened this issue Mar 4, 2019 · 9 comments
Labels
enhancement Improving a current feature help wanted User has a question, not critical

Comments

@v3rbalgit
Copy link

Hi. I was trying to take a look at this library, but it's really hard to work with when there are no typescript definitions on DefinitelyTyped or elsewhere for that matter. There is a nice documentation from JSDoc, but it would be awesome to have types for VS Code Intellisense and autocompletion. Most other libraries like bitcoinjs-lib or bitcore-lib have types. Is there a way to generate types from the source files or how would I go about using this library in VS Code with Intellisense? When I do

const bcoin = require('bcoin').set('testnet');

it doesn't provide any suggestions on the bcoin object. Thanks!

@pinheadmz
Copy link
Member

If you're using latest master branch from GitHub, suggestions should work now:
0e93cba

At least, hitting tab in REPL mode. Not sure about VS Code.

There's been discussions on our slack about converting to typescript but I think the task for a library this size is just too enormous.

@pinheadmz pinheadmz added enhancement Improving a current feature help wanted User has a question, not critical labels Mar 6, 2019
@v3rbalgit
Copy link
Author

I'm on the latest branch, but still can't get the suggestions to work. I tried loading the library in Webstorm, and there most suggestions work out of the box. Although not every instantiated object seem to bear expected methods. For example, in the code from the website, in guide on wallets and accounts, Webstorm will underline the open method in await wdb.open(); or create in const wallet = await wdb.create(); or fromHD in const jdWalletKey0 = WalletKey.fromHD(jdAccount, jdPrivateKey0, branch, index); etc. and warn about an unresolved method or function.

ss

Anyway, I don't own Webstorm, just wanted to try and check Intellisense for this library in another editor. I'm sure building types for a library this size would be a grueling task. But I feel like this is a very important library for JS developers. It has all the bells and whistles as the original C++ implementation and as such it is the best tool to start developing on bitcoin. I'm sure I'm not the only one who would appreciate it immensely. For what it's worth for the past 3 days I have been trying to make myself a sort of faux .d.ts files following the structure from the individual source files (starting with the blockchain module) but for the love of me, I can't get the modules to expose themselves the right way. The only way I can think of is to put everything in one big index.d.ts file. I'm not sure I should be doing this though, as I'm not that familiar with the library and I'm not a fulltime developer let alone a TS expert. All I'm looking for is to expose all the methods and properties of this library so that I can use it with ease and learn bitcoin programming along the way.

@nodech
Copy link
Member

nodech commented Mar 8, 2019

I am not sure if you have tried to configure jsconfig or something like that, I am not familiar with VSCode much. But after couple of experiments I think I was able to achieve what you wanted.

image

image

This is vim + tsserver setup with super simple jsconfig.json:

{
  "compilerOptions": {
		"allowJs": true,
		"module": "commonjs"
  },
	"include": [
		"./**/*.js"
	]
}

Current downside being, require('bcoin') will give you wrapper that caches includes, so you only load whatever is necessary (that's why you will notice I am including whatever I need directly)

Solution:
While this was a workaround on the problem, I believe we can describe jsdoc on lib/bcoin and list all the @propertys bcoin has, you are welcome to open PR listing correct properties on lib/bcoin.

@v3rbalgit
Copy link
Author

This is so strange. I did exactly the same thing as you in VS Code but it doesn't work for me:
bcoin-test
This is what my tsconfig json file looks like:
{ "compilerOptions": { "module": "commonjs", "allowJs": true, "noEmit": true, }, "include": [ "./**/*.js" ] }
The TS compiler raises no errors. So if it works in vim, and it (sort of) works in Webstorm, then there must be a problem with VS Code or something trivial I am missing. It looks like VS Code needs the .d.ts files and won't read the JSDoc syntax out of the box. Can someone with VS Code please chip in how to get this working? It is driving me insane!

@nodech
Copy link
Member

nodech commented Mar 8, 2019

I think you have tsconfig.json instead of jsconfig.json, that could be the issue ?
and you are working with js file instead of ts

@v3rbalgit
Copy link
Author

I tried jsconfig first but it has the same effect, the editor also complained about the allowJS setting then.

@thomaseizinger
Copy link

The next typescript release (3.7), with the final release on November 5th is expected to ship --allowJs in combination with --declaration.

If my understand is correct, this would allow us to setup a typescript project within bcoin, enable allowJs and have tsc automatically emit an initial set of declarations for the project!

@JoePotentier
Copy link

Bump.

@pinheadmz
Copy link
Member

@JoePotentier this is very likely never going to happen. bcoin has no active maintainers. If this is a feature you really want, you may need to write it yourself. 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improving a current feature help wanted User has a question, not critical
Projects
None yet
Development

No branches or pull requests

5 participants