melonJS icon indicating copy to clipboard operation
melonJS copied to clipboard

Type errors and missing properties

Open russellsteadman opened this issue 3 years ago • 5 comments

Describe the bug

When I type checked my files, I noticed quite a few type errors due to inconsistent typings. For example, Renderable's body references the JavaScript DOM document.body type because the type from physics/body.js is not imported.

To Reproduce (Example)

  1. Create an Entity.
  2. Add the Entity to game.world with the addChild method.
  3. Type check the file, Entity.body does not implement Renderable.body.

Expected behavior No type errors for the action.

Version:

  • melonJS Version: 14.3.0

russellsteadman avatar Dec 30 '22 15:12 russellsteadman

It might be useful to switch the source files to TypeScript, and then the issues would be able to be caught automatically and the import type MyDefaultType from ... and import {type MyType} from ... syntax could be utilized. I can make a pull request with these changes if that is something the maintainers would be interested in.

russellsteadman avatar Dec 30 '22 15:12 russellsteadman

I really have no idea on how to fix this, as it does sound like a consequence of switching to separate files when generating the TypeScript definitions files (@see #1162)

but definitely there is no intention to switch the whole source code to TypeScript for now. Maybe an "intermediate" solution would be to have an additional TypeScript within the source file that would contains type definition for all major public classes ? and that files would then be added to the batch of automatically generated d.ts files ? can this work ?

@lartkma by any chance, do you have any idea/suggestions ?

obiot avatar Jan 10 '23 00:01 obiot

The next.js configuration template file has a good example of importing types in JSDoc for pure JS files.

If you don't want to convert the source to TypeScript, it may be good to implement some tests in TypeScript and simply see if the test files pass type checking. This will help with debugging.

russellsteadman avatar Jan 10 '23 01:01 russellsteadman

that interesting ! Since you were proposing it earlier, would be interested in making a pull request for it ? I'm asking as I'm not personally using TS, this way you can verify directly that this working for you ?

obiot avatar Jan 10 '23 03:01 obiot

note that we are using webdoc (https://www.webdoclabs.com) as well for the documentation, which is supposed to also support some TypeScript tags or semantic (not sure how to put it). Now I never tried, but if some are missing @ShukantPal can hopefully help :)

this to say as well that if you do make a pull request and do it by modifying the documentation tags, make sure the doc generation is not broken. just use npm run doc-local and make sure it does not throw you any errors.

thanks a ton!

obiot avatar Jan 10 '23 03:01 obiot

closing this one , see #1199

obiot avatar Apr 14 '24 01:04 obiot