node-ytdl-core icon indicating copy to clipboard operation
node-ytdl-core copied to clipboard

[proposal] Migrate to TypeScript

Open zardoy opened this issue 4 years ago • 8 comments

Why?

I don't know how about other IDEs but it seems that VSCode would show JSDoc hints only if they are declared in TypeScript part (in .d.ts). For example VSCode wouldn't show description for getVideoID. I don't think it's a big inconvenience for everyone but again we could provide a better developer experience with this change 🚀 .

AFAIK TypeScript doesn't have disadvantages and I think it would be much easier to keep everything in one place.

For instance

export const getVideoID = (str: string): string => {
// ...

@fent Do you have any thoughts on this? and do you mind if I show you how it could be done?

P.S. Sorry if I misspelled anything

zardoy avatar Feb 02 '21 19:02 zardoy

yep, i was already planning this, but hadn't recorded it in an issue yet. just need to find the time to 😅

and do you mind if I show you how it could be done?

i've been slowly converting my other active projects into typescript, some examples are miniget and m3u8stream which ytdl uses. my process consists of the following changes

https://github.com/fent/node-miniget/commit/30e0b97ce4c2d5cee410ebe3b85fc48bceb5c03d

is my method similar to what you had in mind?

fent avatar Feb 02 '21 20:02 fent

Yes, you're right. As I can see why section wasn't necessary here 😅 . If you want I could help you with that, because I've got a lot of free time :)

zardoy avatar Feb 02 '21 21:02 zardoy

that would be great!

fent avatar Feb 03 '21 07:02 fent

@fent can I know why do you export them here? https://github.com/fent/node-ytdl-core/blob/e14c9da91fbb383e8cc84fc6dab2febd13ee277d/lib/info.js#L478-L481

zardoy avatar Feb 03 '21 19:02 zardoy

those are all exported by ytdl so that they can be used by users. they're also exported in index.js, but i also want to support someone only importing info.js

fent avatar Feb 03 '21 20:02 fent

Nah, index.js exports them from url-libs.js directly: https://github.com/fent/node-ytdl-core/blob/e14c9da91fbb383e8cc84fc6dab2febd13ee277d/lib/index.js#L30 why user can't import them from entry point directly? 0_o

zardoy avatar Feb 03 '21 20:02 zardoy

Ah, just never mind, it doesn't really matter. I think i could remove this :)

zardoy avatar Feb 03 '21 20:02 zardoy

why user can't import them from entry point directly? 0_o

i wanted to make both available. in another repo i've compiled ytdl-core from info.js, without index.js, and wanted the extra validation functions.

fent avatar Feb 03 '21 21:02 fent