Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct way of adding typescript def files in version ce ? #16

Closed
iangregsondev opened this issue Jan 25, 2017 · 2 comments
Closed

Correct way of adding typescript def files in version ce ? #16

iangregsondev opened this issue Jan 25, 2017 · 2 comments

Comments

@iangregsondev
Copy link

Hi,

I am using webpack with expose-loader to have Phaser etc available on the global scope. Things are working well, I decided to upgrade to phaser-ce and the only way I could get my IDE (webstorm) to recognise that Phaser was actually a type was doing the following in MY tsconfig.json file

  "include": [
    "**/Game.ts",
    "../node_modules/phaser-ce/typescript/phaser.d.ts"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]

Now it does work but says there are Multiple Options i.e. phaser.d.ts and phaser.comments.d.ts and phaser_box2d.d.ts.

I was wondering if I was doing the above correctly ?

I of course decided to remove the Includes section above but then that fails probably due to the fact that I have the exclude node_modules so the types are never being picked up.

I am using typescript 2.1 and decided to try and use the typeRoots but this also failed

"typeRoots" : ["../node_modules/phaser-ce/typescript"]

I am little confused of how to proceed do I leave the "../node_modules/phaser-ce/typescript/phaser.d.ts" inside the include section of the tsconfig.json ? It just feels kind of wrong.

Also even if I use this way then 'Phaser' seems to show Multiple Implementations for Phaser

Any help or info really appreciated

Thanks

@rroylance
Copy link
Contributor

rroylance commented Feb 3, 2017

In your tsconfig.json you just need to add the following;

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

EDIT) Also, I figure I'd leave you my entire tsconfig for reference;

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "sourceMap": true,
    "types": [
      "node"
    ]
  },
  "files": [
    "./src/globals.d.ts",
    "./src/app.ts",
    "./node_modules/phaser-ce/typescript/phaser.comments.d.ts"
  ]
}
  • "./src/globals.d.ts" defines some global constants that are included in my game via webpack (I need the d.ts file so that my code and the compiler knows that those values exist)
  • "./src/app.ts" is my games entry point (where the Phaser.Game is created and the boot state started)
  • "./node_modules/phaser-ce/typescript/phaser.comments.d.ts" is obviously the phaser definitions (phaser.comments.d.ts contains references to pixi.comments.d.ts and p2.d.ts, so you only need to reference the phaser one)

@samme
Copy link
Collaborator

samme commented Apr 1, 2017

Closing this, but if any relevant Phaser docs are incorrect/incomplete, please add an issue.

@samme samme closed this as completed Apr 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants