Discord.js: Typescript definition file

Created on 15 Apr 2016  路  29Comments  路  Source: discordjs/discord.js

Hi,

I'm using discord.js for a bot project of mine written in TypeScript. For now I've made my own typings file (not great/complete) and I was wondering if you're going to provide an official (i.e. made by the contributors of this project) one in the mid/long term?

help wanted enhancement

Most helpful comment

Alright, as I started one I might as well try to complete it and open a PR :smiley:

All 29 comments

I don't think we'll be providing one...

Alright, as I started one I might as well try to complete it and open a PR :smiley:

@chadrien Any progess on this? If you already have something, someone could continue on it if you stopped.

Hi @GexoXYZ: I was absorbed by other things and completely forgot this, sorry! I have something already but it's not perfect and far from complete: https://github.com/chadrien/cycle-discord/blob/master/src/custom-typings/discord.d.ts
Feel free to go ahead from this as I may not have the time to continue working on this in the time being.

Unless someone else is working on this, I'm going to take a stab at it. I'll post any updates here.

I've started writing the definition file. So far it seems functional, however I'm worried that it's not correct. Can anyone take a look and tell me if it looks okay?

https://github.com/Falconerd/discord.js-td/blob/master/index.d.ts

Okay, I've completed an initial version. I haven't written tests for it yet as I'm out of time. When it's all testing properly I'll see if I can submit it to definitely-typed.

https://github.com/Falconerd/discord.js-td/blob/master/index.d.ts

I'm just saving it as typings/discord.js/index.d.ts and it seems to work so far.
Make sure to add the reference path to typings/index.d.ts

Sweet, I'll remove mine as that one is better

As of 9.0.2, the typescript definition would be out-of-date. It'd be great if someone could update it!

Doesn't look like this is going to happen ;(

Why close it? Somebody may attempt it in the future if it stays open.

I'll do it!

Generated this template 99% automatically from docs.json https://gist.github.com/oorooroot/091e392cdc45a995b2fade876980c0cd
Need some review on it, please. Creating typings first time.

@oorooroot how did you do that?

@oorooroot good job.

@oorooroot and thank you very much, I really needed this haha

@oorooroot: Looks really good 馃憤
The comments might be removed though? Looks like it's just a plain copy of code comments, so it might not be necessary in the definition file and it's also "code" (well not really, they're comments) duplication.
But appart from that, nice job! Maybe you could open a PR with this and a modified package.json adding a scripts entry to generate it the way you did so the discord.js team could automate it when they make changes/new releases.

@chadrien i think that comments are necessary for class, member and argumet description, when using definitions in any IDE. I will refactor my script in few days, polishing some things, including better comments.

Im still not sure if it is such good idea, to generate typings from docs. During parsing the docs i found some argument or member types, that are not defined by docs.json or any javascript code in the project(you can found this type definitions at the end of my .d.ts file, VerificationLevel or RoleData for example, all of them typed as any).

There are also some documetation-described types that looks strange for me. As example @returns {Promise<Invite, Error>} here https://github.com/hydrabolt/discord.js/blob/indev/src/client/Client.js#L197
or @returns {Object<string, boolean>} here https://github.com/hydrabolt/discord.js/blob/indev/src/structures/EvaluatedPermissions.js#L24 not sure if Object<string, boolean> is correct definition in js, but in typescript definitions i just replaced with {[K:string]: boolean}(such cases are hardcoded in my script so it is pretty ugly for now).

So there are some "special requirements" to documentation, if we wsnt to get all the things typed 100% automaticaly.

The , mean it can return 2 types. Promise<Invite, Error> means it will either return a Promise with a Invite type or one with an Error type, the corrent way of defining this would be Promise<Invite | Error>

@chadrien I came here to offer to do this also, because I'm in almost the exact same situation, want to convert my bot to TS, need a def file.

Just wanted to point out that the way users acquire typing files has changed in Typescript 2.0
See here for more info
This means publishing a Scoped NPM package (@types/discord.js)

if you need any help, give me a bell, really keen to give back to this project.

@Mischala I would also like an @types package

someone might want to take a look at https://github.com/englercj/tsd-jsdoc. it generates typescript definitions from jsdoc, and we have the entire client documented with jsdoc :)

@GusCaplan I thinks that is what @oorooroot did

@GusCaplan good call, will have to check if @hydrabolt 's jsdocs are read correctly by that tool

@GusCaplan you are a fool.
Full typings for d.js are available here btw: https://github.com/acdenisSK/discord.js-typings

@iCrawl Is there a reason this can't be maintained as part of the original project?
especially with these improvements to the Typescript's typing's acquisition.

0 at all. There was just no PR yet. I will have a talk with him so it will probably be included in indev.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LLamaFTL picture LLamaFTL  路  3Comments

BrandonCookeDev picture BrandonCookeDev  路  3Comments

Dmitry221060 picture Dmitry221060  路  3Comments

shukriadams picture shukriadams  路  3Comments

Alipoodle picture Alipoodle  路  3Comments