foundry-vtt-types
foundry-vtt-types copied to clipboard
Improve actor.itemTypes typing
trafficstars
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:
let weapons = itemsByType['weapon'];
// Then I want to access to the data without additional check:
weapon[0].data.data.<property available weapon>
If I create a globa.d.ts with the following
import {ConfiguredDocumentClass} from '@league-of-foundry-developers/foundry-vtt-types/src/types/helperTypes';
declare global {
class Actor extends ClientDocumentMixin(foundry.documents.BaseActor) {
get itemTypes(): Record<
'weapon',
Array<InstanceType<ConfiguredDocumentClass<typeof foundry.documents.BaseItem>> & {data: {type: 'weapon'}}>
>;
}
}
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 ?