Lowkey been trying to create a module
Lowkey been trying to create a module with the Foundry types but keep funning into issues. Either my tsconfig is never set up right, or when it finally is, then none of my types actually register as types within my project and create build errors (unless I force it to reference things with
/// <reference types="fvtt-types" />
directive at the top of every single .ts file, but that's just kinda really annoying to have to do)
Been bashing my head trying to get the setup for this right for the last couple days and I keep going in circles and dunno what Im really doing wrong here if anyone can help. Attatched tsconfig for reference29 Replies
So what do the errors look like?
Im legitimately only having trouble with my typescript engine just recognizing types, really

Okay I'm not having problems so let me walk through some pre-requisite questions:
1. Have you run
npm install
?
2. What's your npm
/node
version? Get that with npm --version
and node --version
respectively
3. What is your editor's TypeScript version. With VSCode you get that with opening the command pallete (by default that's ctrl+shift+P) and running "Select TypeScript Version". I don't want you to change anything, just report what you currently see. I see 5.8.3Yup, so all the basic stuff.
Node version: 11.4.1
- npm install
- delete node libraries and reinstall
- ctrl+shift+p > restart ts server
Hell, Ive even just now copy/pasted the working example tsconfig from that repo you sent, but it still yells at me in there that its not setup right. The amount of circles Ive gone in to troubleshoot things, ask devs, and just get literally the base-level module with types working is kinda nuts

I think I see the issue lol
Your include was
"scripts/**/*"
but it needed to be "src/scripts/**/*"
These are the edits I'd make:
Even just copy pasting this:

I cri :cat_cry:
try reloading the window
you just reinstalled your node modules
maybe the tsc server needs to catch up
for me it's all working rn
(well besides some errors I'll help you solve)
Restarted window and the tsc server. No dice. Idk, I suppose its at least somewhat relieving to hear that maybe its just my IDE being a dick, really
Can you tell me what's in
node_modules/fvtt-types/
?
like open the folder and screenshot it
Can you try
npx tsc
?Mmm now Im getting those earcut errors. Just shut down the whole thing and booted it back up and the error is gone now in the tsconfig at least
Okay those are to be expected!
sweet
So I'll probably make a more tailored fix for this at some point, so that you don't have to do this
but I'm getting the earcut errors too
Go ahead and add this to your
package.json
:
re-install and then the earcut errors should go away
The issue is that Foundry and PIXI define conflicting types for earcut
. I made a PR to PIXI to fix it but until Foundry updates its PIXI version I can't update
You will immediately run into another issue which I have pre-empted the fix for but let me know if the earcut issues go awayCool. I can actually see the game and .settings property too being typed now which is awesome.
Second question I had was on the registering of settings? Before I would just do this:
But currently get errors because I suppose the register method changed types and expects something different?

Yeah! That's what I was pre-empting
I couldn't figure that bit out for sure haha
Create a file like
configuration.ts
and write this:
this configuration.ts
file is for letting fvtt-types know about common things it can't just track for youI tried doing something like that in the src/types directory? Did I set that up correctly?
Ahhh
Yeah, that changed at the tail end of v12, my bad
should've looked for that
No prob no prob
Should I change it to declare module instead? (And the Settings Config type?)
Yeah
You can get rid of the type argument to register at that point
e.g.
settings.register<string>
-> settings.register
it'll "just know"
I noticed you do game.settings!
a fair bitYeah, was kinda because of a lot of these issues I've been having lolol
Literals were the only way to get it working properly for some reason
They're typed as nullish too. It's not possible at runtime because you're in
"ready"
but unfortunately fvtt-types can't tell that.
1. Set up a getGame
function or something similar in order to safely get game
. Common options are to throw if game
doesn't exist or have an async function that waits.
2. Add interface AssumeHookRan { ready: true }
in declare module "fvtt-types/configuration"
in your configuration.ts
fileSounds good!
Well at long last, things build, so Im happy with this currently. Im sure I might have some questions in the future, so Ill come back here into this thread just in case so I dont clutter up things in the future if there is
You've been super helpful!
glad I could help!
if there's no conversation going on no need to thread
and open a new thread, else I might not see
Sounds good!
This tsconfig has a lot of goodies imo btw: https://github.com/LukeAbby/foundry-starter-template/blob/main/tsconfig.json
GitHub
foundry-starter-template/tsconfig.json at main · LukeAbby/foundry-...
An opinionated starter template. Contribute to LukeAbby/foundry-starter-template development by creating an account on GitHub.
In particular,
noUncheckedIndexedAccess
, forceConsistentCasingInFileNames
, noUncheckedSideEffectImports
and more I feel all should be on in basically all projects