Jump to content

Phaser 3 JSDoc Generated Typescript Definitions


Recommended Posts

I haven't tested everything yet but using my modified version of Antriel's official (WIP) Phaser 3 typescript definitions build, I was able to get scene properties (plugins) to work using a hacky generator by stepping through Phaser code with the browser debugger, converting any useful runtime data to JSON, writing it to disk, then converting it with a simple script, and injecting it into Antriel's build. 

End result: Everything appears to be compiling in the typescript compiler so far, with code hinting, autocompletion/intellisense, ect. in VS Code (and I imagine similar editors).

Note: This is a temporary, hacky, potentially unstable solution for those who want to start building their Phaser 3 typescript projects right now while we wait on offical typescript support to be completed by Antriel and the Phaser team.

Modified build here: 
https://github.com/troyedwardsjr/phaser3-tsd/blob/master/build/official/phaser.d.ts

Also created a boilerplate starter project, with definitions included:
https://github.com/troyedwardsjr/phaser3-typescript-webpack

GIdIa5q.png
YuzMdYi.png
k5kyhnA.png
5ARF0u3.png

Link to post
Share on other sites
1 hour ago, Ppozniak said:

Great! That's what I've been looking for, but can you use this without TypeScript in VSCode using IntelliSense?

I believe so. One way I know of is copying the typescript definition file to the root of your phaser folder in node_modules, and changing the phaser package.json file to have the field "types" : "./phaser.d.ts" in it.

Then either restart the TypeScript server in VS Code by pressing CTRL + SHIFT + P and searching "Restart TS Server" or just restarting VS Code. So as long as you're using NPM and RequireJS or ES6 Import, you should be able to use it with vanilla Javascript or ES6.

https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html
https://code.visualstudio.com/docs/languages/javascript

qEoAQDp.png

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...