[Question] Whats the "right" way to consume typescript definitions?
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 👍
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.
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" />
AFAIK you don't need the /// ref anymore.
@thosakwe, yes, you're right. Works just fine without them. Thanks.
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?
Download it into your project root, like mentioned above, not node_modules. That for sure works.
@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.