BraveyJS / Bravey

A simple JavaScript NLP-like library to help you creating your own bot.
https://braveyjs.github.io/
MIT License
78 stars 6 forks source link

Create a TypeScript definition file (.d.ts) #13

Open thiagodp opened 7 years ago

thiagodp commented 7 years ago

It would be nice to have a definition file (.d.ts) for TypeScript. It would also help non-TypeScript developers to understand the API.

nippur72 commented 6 years ago

As part of understanding this awesome library, I've written type definitions for the most basic objects.

You can view/use them by installing Bravey from my fork (branch typedefs):

npm install git://github.com/nippur72/Bravey.git#typedefs --save

If I ever get to finish them, I will do a PR, but there are part of the library I still have to understand (ContextManager, ApiAi...).

thiagodp commented 6 years ago

Nice! I look forward to the PR ;) Maybe @BraveyJS may help you with some details about the API.

nippur72 commented 6 years ago

One problem I'm facing is that all objects are not classes as I thought, so my definitions are all wrong if you try to subclass something. For instance you can't extend any of the EntityRecognizer the ES6 way.

nippur72 commented 6 years ago

Ok, I've fixed the types using interface and new()=> instead of class, so now it should work correctly. But still it's annoying to subclass due to methods being injected in this instead of this.prototype.

Is there any plan/roadmap to convert it to ES6 ?

BraveyJS commented 6 years ago

Thank you @nippur72 for making typescript interfaces! It's a very interesting feature and I'd like to squash it as-is ASAP ;)

Sadly we don't use typescript so much, so I'm asking if there is a way to test - or put together a unit test - for checking if this interface works, in order to check when/if it will break in the future.

nippur72 commented 6 years ago

I think the only way is to write some typescript code that uses the library and then asserting that the tsc compiler is able to compile it without warnings.

I'll try to write a script to automates it.

thiagodp commented 6 years ago

I'm using a customized version of Bravey in a typescript project. I can use the new definition files and provide some feedback.

thiagodp commented 6 years ago

I verified bravey.d.ts with my typescript project and I didn't get any warnings.