jonobr1 / two.js

A renderer agnostic two-dimensional drawing api for the web.
https://two.js.org
MIT License
8.31k stars 455 forks source link

[Bug] Missing some constructors in types.d.ts #620

Closed queuedq closed 2 years ago

queuedq commented 2 years ago

Describe the bug Some classes like Rectangle or Circle don't have a constructor declared in types.d.ts. Since they inherit from Path, the constructors for them default to the Path's constructor. However, their constructors are different from the Path's constructor.

To Reproduce

import Two from 'two.js';

const rect = new Two.Rectangle(0, 0, 100, 100);
// Error: Argument of type 'number' is not assignable to parameter of type 'Anchor[]'.

Environment (please select one):

I'm using Parcel with TypeScript.

tsconfig:

{
  "compilerOptions": {
    "target": "es6",
    "module": "es2020",
    "jsx": "react",
    "lib": ["dom", "es6"],
    "plugins": [{ "name": "typescript-plugin-css-modules" }]
  }
}
jonobr1 commented 2 years ago

Thanks for posting @queuedq. Mind giving the latest dev branch a try and see if that fixes the issue?

You can do that like so:

npm install --save https://github.com/jonobr1/two.js

If it's good on your end then I can publish a new version to NPM

queuedq commented 2 years ago

Thank you for the quick response!

After installation, I imported two.js like this:

import Two from '@jonobr1/two.js';

But it emits the following error message.

File '(...)/node_modules/@jonobr1/two.js/types.d.ts' is not a module.

I guess it's due to a name mismatch and it should work without problems after publishing, though. (Is there a way I can test it?)

Edit: I set compilerOptions.paths and the types are working great! But I can't run it with Parcel, so I'll wait for the release.

jonobr1 commented 2 years ago

Ah, right because everything is expecting @jonobr1/two.js not two.js. I'll push the release now.

jonobr1 commented 2 years ago

Okay that's up: https://www.npmjs.com/package/two.js

Thanks again for you posting.

queuedq commented 2 years ago

It works fine now, thank you!

jonobr1 commented 2 years ago

Glad to hear! Thanks again for reporting