-
Notifications
You must be signed in to change notification settings - Fork 56
FAQ
- How do I make the Foundry VTT Types recognize the data layout I have defined in my
template.json
file? - I'm using a custom document class, how do I make the Foundry VTT Types recognize that?
- Why can't I access any properties on
game
/canvas
? - How do I create my own
FormApplication
? - I am using
npm 6
oryarn
and getting compile errors related to@pixi/smooth-graphics
How do I make the Foundry VTT Types recognize the data layout I have defined in my template.json
file?
Take a look at Actors and Items which includes detailed instructions regarding that.
Take a look at Custom Document Class Configuration which includes detailed instructions regarding that.
Foundry VTT initializes these global variables right before the 'init'
hook event. However, it is possible for modules / systems to access these variables in code that runs before the 'init'
hook event (code that runs on the module / script level), so we need to include their uninitialized states in their types. To mitigate this, there are a couple solutions:
- Add a type guard when trying to access these variables:
if(game instanceof Game) { // whatever you wanted to do with `game` } else { throw new Error('game not initialized yet!'); }
- It is cumbersome to do this at every place where you want to access these variables. A solution for that is to create a wrapper around the variable you want to access, do the type guarding in there, and then just use the wrapper in the rest of your code instead of using the variable directly:
function getGame(): Game { if(!(game instanceof Game)) { throw new Error('game is not initialized yet!'); } return game; } // somewhere else in your code: getGame().i18n.localize('...'); // or whatever else you wanted to do with game
- If this is still to cumbersome to you, there is another way out: We added a way to configure a couple of global vaiables to be typed as their initialized states with the help of declaration merging (see A Quick Guide to Declaration Merging for a short introduction on what that is and on how you can use it to work around possible mistakes in the type definitions). All you need to do is globally declare the interface
LenientGlobalVariableTypes
with properties called like the variables that you want to be typed more leniently (the types of the properties don't matter). Currently, the variablesgame
,socket
,ui
andcanvas
are supported. Here is an example that shows how to do this forgame
:declare global { interface LenientGlobalVariableTypes { game: never; // the type doesn't matter } } game.i18n.localize('...'); // or whatever else you want to do with game, works fine now! :)
- You can automatically get the solution from 3. for all global variable types by using the separate entry file
@league-of-foundry-developers/foundry-vtt-types/index-lenient
instead of@league-of-foundry-developers/foundry-vtt-types
in yourtsconfig.json
:If you don't care that much about safety, this is probably the most convenient solution"types": ["@league-of-foundry-developers/foundry-vtt-types/index-lenient"]
Take a look at Creating custom FormApplications.
This is most likely related to some peer dependencies missing, as peer dependencies are not installed automatically by yarn
and npm 6
(npm >= 7
does install them automatically). To solve the problem, simply add the missing dependencies to your devDependencies
:
"@pixi/constants": "6.2.1",
"@pixi/core": "6.2.1",
"@pixi/display": "6.2.1",
"@pixi/graphics": "6.2.1",
"@pixi/math": "6.2.1",
"@pixi/runner": "6.2.1",
"@pixi/settings": "6.2.1",
"@pixi/utils": "6.2.1",