bugout icon indicating copy to clipboard operation
bugout copied to clipboard

Support for TypeScript

Open tanayseven opened this issue 5 years ago • 23 comments

I really want TypeScript support for Bugout. I'm willing to add it and raise a PR. Do you think I should raise PR in this repo? Or should I raise PR in the Definitely Typed repo?

tanayseven avatar Jan 13 '21 14:01 tanayseven

@tanayseven sounds good. What does TypeScript support involve? Can you give me a brief overview of what would need to be added to the codebase?

chr15m avatar Jan 15 '21 02:01 chr15m

The major addition would be a type declaration file. <something>.d.ts. Some minor changes would include installation of TypeScript related packages and some typescript related config in the package.json file. The existing code will mostly be untouched.

For more details please refer the documentation

The changes can either be done in two ways. First is in this repo which means that this repo will be self sufficient when it comes to typescript. The other way would be to add the type declarations in the Definitely Typed repo. Which means that library consumer will have to install two separate repositories.

tanayseven avatar Jan 15 '21 03:01 tanayseven

@tanayseven thank you. Let me have a think about the tradeoffs.

chr15m avatar Jan 15 '21 03:01 chr15m

Hey @chr15m, did you get a chance to decide on whether to go ahead or not based on the tradeoffs?

tanayseven avatar Jan 18 '21 17:01 tanayseven

@tanayseven where can I find in the documentation which packages will need to be added to the package.json file?

chr15m avatar Jan 20 '21 08:01 chr15m

@chr15m I think all you need is the typescript package and nothing else. In addition to that there might be a couple more changes to the package.json file. The documentation as you requested

tanayseven avatar Jan 20 '21 10:01 tanayseven

@tanayseven if it can be done without adding typescript to the packages (only a ...d.ts file) then go ahead and PR to add it here, but if it requires a package many people won't use, then I think it's best to submit to Definitely Typed.

chr15m avatar Jan 23 '21 09:01 chr15m

I think it should be possible without the typescript package and just by adding a ...d.ts file and adding a line to package.json. Let me fork the repo and test it on my side. If it works, I'll raise a PR. Till then let's keep this issue open.

tanayseven avatar Feb 01 '21 07:02 tanayseven

I'll be busy for a couple of weeks, requesting you to keep this issue open till I return

tanayseven avatar Feb 15 '21 17:02 tanayseven

@tanayseven no trouble, happy to leave the ticket open. Thanks for looking at it.

chr15m avatar Feb 15 '21 22:02 chr15m

I was trying to add types to my personal project which I will later transfer to the bugout repo. I was trying to stringify the bugout object using typescript to debug it. But when I do that it gives the following error.

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'WebTorrent'
    |     property 'torrents' -> object with constructor 'Array'
    |     index 0 -> object with constructor 'Torrent'
    --- property 'client' closes the circle

Is there a cyclic dependency in the implementation of bugout? If yes, can that be fixed? I think cyclic dependencies with come back to bite us in the future.

tanayseven avatar Apr 09 '21 19:04 tanayseven

trying to stringify the bugout object using typescript to debug it

Can you output it to the browser console and inspect it there? The referencing cycle you're referring to appears to be in the WebTorrent library, not Bugout, and I don't think they would consider that a bug.

chr15m avatar Apr 10 '21 03:04 chr15m

Sorry, I removed that code while trying something else, so I'm unable to reproduce it. As of now assume that issue does not exist. I'll go ahead with adding the type definitions till then.

But as far as I remember, the error looked exactly like the text that I've posted above. Since I was trying it in Svelte.

tanayseven avatar Apr 10 '21 18:04 tanayseven

Let me know how I should test it before merging. I was unable to manually add to my actual project's node_modules and check if it works.

tanayseven avatar Apr 10 '21 18:04 tanayseven

You might be able to use the npm link command to test it.

chr15m avatar Apr 11 '21 04:04 chr15m

Things are a bit stressful in my country, India. It will take a while for me to contribute to this. It's currently hard for me to take time out for doing this.

tanayseven avatar May 02 '21 15:05 tanayseven

@tanayseven I completely understand and please do not feel any obligation to work on this ticket.

chr15m avatar May 03 '21 06:05 chr15m

Thanks a lot

tanayseven avatar May 04 '21 11:05 tanayseven

Need this too

zisra avatar Nov 20 '23 23:11 zisra

@zisra patches welcome!

chr15m avatar Nov 21 '23 01:11 chr15m

@chr15m there's already an open PR though. There's some things missing to it, should I open a new one?

zisra avatar Nov 21 '23 01:11 zisra

@zisra whatever is easiest for you. I know nothing about typescript and I think the original contributor does not have capacity to take it further.

chr15m avatar Nov 21 '23 02:11 chr15m

Typescript is worth the trouble of a migration. You can indentify lot of issues usually raised in runtime , before even use the lib.

Tried today to start a refactor of the lib that uses typescript. And found some issues for example in opts argument in Bugout.

In typescript side , whatever we write in the code , it should be defined and makes some meaning somehow , while Js let us to write more arbitary code.

@chr15m tomorrow i ll push the current version in my fork , if you want to elaborate to fix those issues there , and see what im talking about..

Kos-M avatar Feb 19 '24 00:02 Kos-M