Skip to content

Support proper fix for types #1071

Description

@Coder2195

Im using TypeScript

And this happens

image

And looking at the d.ts file results in 10+ errors

image

As well as the ANY types here
image

Activity

  1. parasyte commented on Feb 18, 2022

    @parasyte
    Collaborator

    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 target field.)

    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:

    melonjs-typescript

    And you can run tsc in your shell (assuming npm install -g typescript) to get all the same info:

    melonjs-tsc

    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 me namespace with proper es2015 modules. Most of the work was completed as of #1021, but this legacy namespace thing persists.

  2. obiot commented on Feb 19, 2022

    @obiot
    Member

    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#L1819

    but 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.

  3. added a commit that references this issue on Feb 22, 2022
  4. obiot commented on Feb 22, 2022

    @obiot
    Member

    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 !

  5. obiot commented on Feb 23, 2022

    @obiot
    Member

    with the few last commits today, we have now 0 warnings and 0 errors on the typescript definition file 🥳 🎈 🍺

    Screenshot 2022-02-23 at 3 57 34 PM

    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 !

  6. Coder2195 commented on Feb 23, 2022

    @Coder2195
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions