Repository navigation
Support proper fix for types #1071
Description
Activity
I'm not an active maintainer on this project anymore, but recently with my other JS projects I have been using vanilla JS with jsdoc type annotations for TypeScript linting in IDEs. melonJS is already well-documented with jsdoc style comments, and adding types is a big commitment. But it less work than translating the whole project to TypeScript.
It's pretty easy to get started. Create a new file in the root called
tsconfig.json:{ "compilerOptions": { "allowJs": true, "checkJs": true, "strict": true, "target": "es2015" }, "include": [ "dist/**/*.ts", "src/**/*.js" ] }(If you have increased your ECMAScript level to a more recent version, just change the
targetfield.)And then install the TypeScript addon for your IDE, that's it! You can also configure the addon to show type errors in various ways, depending on the IDE. For example, I use Sublime Text, and this is how I have it configured:
And you can run
tscin your shell (assumingnpm install -g typescript) to get all the same info:The best part about this setup, IMHO, is there is no need to run any build commands. Import the source code directly as a module and away you go!
Just thought I would throw that out there. melonJS still isn't 100% TypeScript compatible, as far as I know. Adding the TypeScript config and using it as a lint will go a long way to improving that, though! The biggest challenge that I can see for this is replacing the antiquated
menamespace with proper es2015 modules. Most of the work was completed as of #1021, but this legacy namespace thing persists.the TS Definition file is indeed built based on the JSDoc Tags, but yes it still needs more reworking to output a clean definition. In the latest commits, most (if not all in theory) object constructor now have proper typings, see here :
https://github.com/melonjs/melonJS/blob/master/dist/melonjs.module.d.ts#L1819but we still have that me namespace to indeed be removed from jsdoc, it's almost there, especially again with those last commits where most of the documentation was properly update to document es2015 classes.
- added a commit that references this issue
on Feb 22, 2022 Hi Guys,
so in the last commits, I updated the documentation and removed all traces of the legacy me namespace (only remaining now is in the examples). this greatly help with TypeScript in removing most of the errors we had previously.
@Coder2195Text if you have any time to give it a look, the latest distribution file is up to date here : https://github.com/melonjs/melonJS/blob/master/dist/melonjs.module.d.ts
only few errors now are some missing namespace and some warning, but I think it should be much more easy to use TS with melonJS now, let me know !
with the few last commits today, we have now
0warnings and0errors on the typescript definition file 🥳 🎈 🍺For testing, same as yesterday, while waiting for the 10.4 version to be published, I updated the distribution files on Github:
https://github.com/melonjs/melonJS/blob/master/dist/melonjs.module.d.tswould be great to get some feedback/confirmation, but in the mean time I will therefore close this ticket !
Reacted by Pascal- Thanks for the update! It is greatly appreciated!…Sent from my iPhoneOn Feb 23, 2022, at 2:58 AM, Olivier Biot ***@***.***> wrote: with the few last commits today, we have now 0 warnings and 0 errors on the typescript definition file 🥳 🎈 🍺 For testing, same as yesterday, while waiting for the 10.4 version to be published, I updated the distribution files on Github: https://github.com/melonjs/melonJS/blob/master/dist/melonjs.module.d.ts would be great to get some feedback/confirmation, but in the mean time I will therefore close this ticket ! — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.Reacted by Olivier Biot
Im using TypeScript
And this happens
And looking at the d.ts file results in 10+ errors
As well as the ANY types here
