phaser3-docs icon indicating copy to clipboard operation
phaser3-docs copied to clipboard

[Question] Whats the "right" way to consume typescript definitions?

Open bradtaniguchi opened this issue 7 years ago • 7 comments

Hi, First Id like to thank the dev team for providing the definitions in the first place, it helps a lot 😄

Now, I have a question about using the generated typescript definitions that appear within typescript/phaser.d.ts. Whats the expected/cleanest way to get going with the type definitions in a typescript environment?

Currently it seems like the "easiest" way is to copy-paste the definitions into a local folder of my project (like ./types) But it seems really manual, and I was just wondering if there is a cleaner way to utilize the definitions? Thanks, and I'm so far loving the changes made to Phaser with phaser3 👍

bradtaniguchi avatar Jun 17 '18 21:06 bradtaniguchi

I've had success just wgetting the phaser.d.ts file into my project root, and then TypeScript picks it up automatically. It might seem "really manual," but IMO it's a lot less complicated than using a package manager, especially NPM.

thosakwe avatar Jun 20 '18 22:06 thosakwe

In package.json I have:

 "dependencies": {
    "phaser": "^3.10.1",
    "phaser-docs": "photonstorm/phaser3-docs#5cea38c",
   ...
 } 

In tsconfig.json:

{ 
  ...
  "files": [
    "node_modules/phaser-docs/typescript/phaser.d.ts"
  ]
}

and in main.ts:

/// <reference path="../node_modules/phaser-docs/typescript/phaser.d.ts" />

Aivean avatar Jun 23 '18 21:06 Aivean

AFAIK you don't need the /// ref anymore.

thosakwe avatar Jun 23 '18 21:06 thosakwe

@thosakwe, yes, you're right. Works just fine without them. Thanks.

Aivean avatar Jun 23 '18 21:06 Aivean

I was able to get the repo using this command: npm install --save photostorm/phaser3-docs instead. Which downloaded the repo to node_modules, and I added the file to the files attribute of my tsconfig.json like this:

"files": ["node_modules/phaser3-docs/typescript/phaser.d.ts"]

But I'm still getting the tslint error "Could not find declaration file for module phaser". Am I missing something else with this setup?

bradtaniguchi avatar Jul 04 '18 20:07 bradtaniguchi

Download it into your project root, like mentioned above, not node_modules. That for sure works.

thosakwe avatar Jul 04 '18 20:07 thosakwe

@thosakwe Yea, I know it works, but it seems like the least optimized option. I like the idea of getting it thru npm/github links and versioning it thru our package.json, but in the mean time I have a manual solution, but I'd be left to believe there is a better way.

bradtaniguchi avatar Jul 06 '18 02:07 bradtaniguchi