drawcall / Proton

Javascript particle animation library
https://drawcall.github.io/Proton/
MIT License
2.42k stars 275 forks source link

Typescript usage #83

Open DjulLau opened 3 years ago

DjulLau commented 3 years ago

Hi there,

First thanks for this great lib ! I've used it some years ago in pure JS with success. Now I'm trying to use it in a typescript project with no luck. I've just installed it with npm and tried to run the example but I'm getting lots of errors like if the types were not in sync or so.

image

What am I missing ?

Thanks,

Julien

fantasticsoul commented 3 years ago

image

Click Proton constructor type declaration to see detail types definition.

DjulLau commented 3 years ago

Thanks for your answer. I know where to look for the definitions. I don't understand why the basic example generate so many errors (and so my old JS proton codes). Versions incompatibilities ? Wrong/incomplete types definitions ?

drawcall commented 3 years ago

Please download the latest version of proton and try

dgoemans commented 2 years ago

Still doesn't help (using 5.3.2). Looks like the types are incorrect/don't match optional or polymorphic paramters:

For example, the addBehaviour function takes in a Behaviour array, but at no point does color implement a Behavior interface, so you can't call it with a Color.

    /**
     * add the Behaviour to particles;
     *
     * you can use Behaviours array:emitter.addBehaviour(Behaviour1,Behaviour2,Behaviour3);
     * @method addBehaviour
     * @param {Behaviour} behaviour like this new Color('random')
     */
    addBehaviour(...args: Behaviour[]): void;

Same goes for many different functions/constructors/etc

Are the types generated or hand crafted?

fantasticsoul commented 2 years ago

Are the types generated or hand crafted?

sorry, most of d.ts file content is generated by dts-gen, only a few part is written by hand, we appreciate it if you can help us to improve this d.ts file。