Open Socolin opened 2 years ago
I haven't checked every detail yet but we could potentially make this work by using
get itemTypes(): {
[Key in foundry.documents.BaseItem['data']['type']]: Array<
InstanceType<ConfiguredDocumentClass<typeof foundry.documents.BaseItem>> & {
data: foundry.data.ItemData & { type: Key; _source: ItemDataSource & { type: Key } };
}
>;
};
The above makes your example work, but I am not sure if there are any negative implications of that. We will need to check.
Regarding your questions:
interface
to use declaration merging here. However, that still won't work because successive declarations of the same property need to have the same type.Tests are still passing, which sounds promising. Any opinions / comments on this @kmoschcau @FloRad?
Unfortunately, this change breaks other stuff, see #1588, so we are going to revert it for now, until we find a solution.
Just and idea, maybe there could be some kind of config to enable this, like for game
with
let game: 'game' extends keyof LenientGlobalVariableTypes ? Game : Game | {};
Just and idea, maybe there could be some kind of config to enable this, like for
game
withlet game: 'game' extends keyof LenientGlobalVariableTypes ? Game : Game | {};
I don't think that's a practical solution. I agree that it's good to make stuff configurable for common situations but so far, this seems more like a niche thing, so I don't think it's worth the added complexity.
I'll just leave this issue open for now in case we find a solution, but we won't work actively on this.
Hello,
I don't know if typescript allow it but could it be possible to automatically types items of
actor.itemTypes
:When I'm accessing to types like:
If I create a globa.d.ts with the following
it seems to work but I'm getting an error on
class Actor
TS2300: Duplicate identifier 'Actor'
1- Why am I getting an error
class Actor
could you provide an example type merging with more complex case in: https://github.com/League-of-Foundry-Developers/foundry-vtt-types/wiki/A-Quick-Guide-to-Declaration-Merging ? 2- Is there a way to make it available for all types without having to define each overload manually ?