Skip to content

Getting Started with these Type Definitions

Andrew Krigline edited this page Jul 16, 2021 · 2 revisions

Core Assumptions:

  • These are expected to be installed beside foundry-vtt-types.
  • These do not fully type the methods marked private on Document classes, nor some of the private functions in the system files.

These are generated types created from the jsDoc of the system, as such they may be incomplete or just plain wrong. Please open an issue if you find something about that. We recommend resorting to some Declaration Merging if you encounter issues as well.

Installation & Setup

Instructions on the readme

Using the Types

If that's set up, you should be able to access types for things like Actor5e and Item5e now. More importantly, the contents of collections like game.actors.contents will properly be typed as Actor5e. (Please take note of the proper way to access game from foundry-vtt-types)

Item and Actor type

Actor5e and Item5e are complicated to type correctly because of the various types they entail. Simply getting an item and then looking for its spell level isn't going to be good enough to satisfy typescript.

image

Instead you'll probably need to introduce some type guards now:

image

The DND5e namespace

There is a namespace: DND5e which contains types for all of the 'string enumerables' that are defined in dnd5e/config.js. These are not typescript enums as that would not correspond to the runtime types.

They are however useful types for prompting when doing things like this:

image