Minimal.... Nah Maximal FVTT types for TRL

Heya... @Faey, @Vauxs, and others interested in discussing / iterating on some common / minimal types for the areas of the core Foundry API that are touched by TRL. I am starting a new repo / project types-core. providing the minimum amount of core types useful in fulfilling interface aspects. This will be exposed in the runtime library via a new sub-path export #runtime/types/fvtt . I'd like to get a rough version up today. Some of it will just be pulling a minimal set of things from the v12 community types, but making sure things / distributed in a way that makes sense for TRL. At least with the AppV1 Application class things should be firmly defined. A lot of the reasons why I haven't put an emphasis on this area is that at the surface it may seem simple, but can turn into a rabbit hole of general complexity depending on how one tries to combine anything defined in TRL with other types say from PF2E or the community types. So it would be of great benefit to have this be a more collaborative process involving those who are using TS for package dev.
33 Replies
Vauxs
Vauxs•2mo ago
With the plain Application types I think it wont be a problem to combine with pf2e types, but I will see it once I'm back on PF2e Graphics work.
TyphonJS (Michael)
TyphonJS (Michael)OP•2mo ago
Yeah.. It would be really great to get feedback as I don't really have the time to investigate how things would interact with the PF2E types.
TyphonJS (Michael)
TyphonJS (Michael)OP•2mo ago
So what Foundry types am I supposed to even use... The current released beta of the community types from 3 days ago doesn't seem to be functional. I know there are still issues w/ the latest v12, but what do you use @Vauxs?
No description
TyphonJS (Michael)
TyphonJS (Michael)OP•2mo ago
I'm leaning towards this being a colossal waste of time. I'm going to improve / provide more FVTT core types for various type aliases / typedefs that were loosely referenced from the global scope previously. I ship types for practically all of TRL. Most of these problems in respect to the AppV1 infrastructure will be moot in ~6 months when I get closer to releasing the TRL app framework. I can control the types 100% at that point. If someone can provide me with working Foundry types / repo example maybe I can continue to attempt to get essential support in SvelteApplication.
I'm pretty sure most of the TS heads don't realize how seamless the WebStorm intellisense is and that it works painlessly with Foundry. It provides plenty of coverage of the core API; at least enough to write bug free code if you have a modicum of knowledge about the Foundry API. So... I have made a lot of progress.. Still getting the errors from the above image though it doesn't cause build problems. Is there a particular version of the community types that are recommended or what are folks using that doesn't give misleading errors? I should have a nice improvement for those using TS. There will simply be an ambient import that you include in your main entry point:
import '#runtime/svelte/application/ambient';
import '#runtime/svelte/application/ambient';

Any suggestions on a better sub-path name? SvelteApplication can even take the Options generic. All of the base Application methods and data are exposed along with all of the additional SvelteApplication API. Still cleaning some things up. It would be rather helpful if someone can suggest a solid community types build or other solution though. The latest v12 beta is whack.
Vauxs
Vauxs•2mo ago
I specifically use PF2e types and any community made ones stemming from them I do not use types made by the League
Vauxs
Vauxs•2mo ago
Here is one https://github.com/7H3LaughingMan/foundry-pf2e I posted before in #dev-lounge
GitHub
GitHub - 7H3LaughingMan/foundry-pf2e
Contribute to 7H3LaughingMan/foundry-pf2e development by creating an account on GitHub.
TyphonJS (Michael)
TyphonJS (Michael)OP•2mo ago
Cool... That works much better and the same approach for the ambient declarations hooking up SvelteApplication works. With a few things added to SvelteApplication it's pretty minimal. Looks like things will be cooking now... Any suggestion though on a clearer name for the sub-path import. I think #runtime/svelte/application/ts-ambient might be just a bit better.
Vauxs
Vauxs•2mo ago
Sounds good And glad it works!
TyphonJS (Michael)
TyphonJS (Michael)OP•2mo ago
There was gnashing of teeth... 😄 That is a toothless smile...
Vauxs
Vauxs•2mo ago
🙂
TyphonJS (Michael)
TyphonJS (Michael)OP•2mo ago
Err damn conversion :D ;P
Vauxs
Vauxs•2mo ago
This is why I disable that feature lol Different moods entirely
TyphonJS (Michael)
TyphonJS (Michael)OP•2mo ago
Any trick for the dev server and having the entry point be index.ts instead of index.js? Looks like the entry point needs to be index.js to load in the dev server.
Vauxs
Vauxs•2mo ago
Nope, that's what I did for pf2e graphics and have recommended to others. If I knew some way to do it otherwise I'd do it 😩
TyphonJS (Michael)
TyphonJS (Michael)OP•2mo ago
Add a proxy rule to server:
{
server: {
proxy: {
// Rewrite incoming `index.js` request from Foundry to the dev server `index.ts`.
[`/${s_PACKAGE_ID}/index.js`]: {
target: `http://localhost:30001/${s_PACKAGE_ID}/`,
rewrite: () => '/index.ts',
},
}
}
}
{
server: {
proxy: {
// Rewrite incoming `index.js` request from Foundry to the dev server `index.ts`.
[`/${s_PACKAGE_ID}/index.js`]: {
target: `http://localhost:30001/${s_PACKAGE_ID}/`,
rewrite: () => '/index.ts',
},
}
}
}
Faey
Faey•2mo ago
sorry, I'm late to the party! I was out for a few days, got back yesterday and crashed entirely, switching to pf2e types so I can properly use the new ones with league types we are running into ye-olde TS type instantiation bug
Faey
Faey•2mo ago
I am still getting bothered by this lovely result right here:
No description
Faey
Faey•2mo ago
I don't think this is easy to type, as the property is very much required for SvelteApplication to work If there is some typescript magic that could check if the class' default options contains "class" and make it optional in the constructor that would be fantastic But I don't think there is
TyphonJS (Michael)
TyphonJS (Michael)OP•2mo ago
Wouldn't hurt to check out the template repo: template-svelte-ts. Not sure what you are trying to do not loading a Svelte component. It's the only non optional property in svelte configuration object.
Faey
Faey•2mo ago
basically, I want the application to take options some data on init the class is defined in defaultOptions
TyphonJS (Michael)
TyphonJS (Michael)OP•2mo ago
If you are adding props in the constructor or elsewhere, but defining a class property in defaultOptions then what exactly is the problem? You can likely also use Partial<TJSSvelteConfig> if you are typing things somewhere else.
Faey
Faey•2mo ago
That error pops up if I then instantiate the class with the default constructor and try to pass in props that's the class
Faey
Faey•2mo ago
No description
Faey
Faey•2mo ago
pretty minimal as all it does is set some defaults this is the usage
Faey
Faey•2mo ago
No description
TyphonJS (Michael)
TyphonJS (Michael)OP•2mo ago
Also props and context can be a function that is invoked with the this of the app instance; it's not async though. Have NotificationCenter options be typed as Partial<SvelteConfig>. Well.. hmm... Let me take a look.
Faey
Faey•2mo ago
also I can do this:
No description
Faey
Faey•2mo ago
but it feels roundabout now I am setting the class property twice
TyphonJS (Michael)
TyphonJS (Michael)OP•2mo ago
You don't have to use defaultOptions in that case.
Faey
Faey•2mo ago
this is a bit of an unsolvable though because the class property can only be optional in the constructor, if the class has a derivative that sets default options so it does make sense to require it to exist if the svelte settings object is created true, I could do it all in the constructor for classes where I need this
Faey
Faey•2mo ago
No description
Faey
Faey•2mo ago
arrived at this for now Oh I should mention though, partial is not nested, it only applies directly to the properties of the type it's on So while Options is Partial, the contained TJSSvelteConfig is not partial I don't know if this is intentional, so I thought I'd mention
TyphonJS (Michael)
TyphonJS (Michael)OP•2mo ago
Yep.. On partial... Definitely check out template-svelte-ts though for the changes / basic example on how to type things especially w/ the #external context.

Did you find this page helpful?