Package Exports
- foundryvtt-dnd5e-types
- foundryvtt-dnd5e-types/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (foundryvtt-dnd5e-types) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Foundry VTT DnD5e Types
Comprehensive TypeScript type definitions for the DnD5e system in Foundry VTT.
Description
This package provides comprehensive TypeScript type definitions for the DnD5e system in Foundry VTT. It is designed to be used alongside the @league-of-foundry-developers/foundry-vtt-types package, which provides type definitions for the core Foundry VTT API.
The type definitions are automatically generated and updated from the official DnD5e system code, ensuring they stay in sync with the latest features and changes.
Compatible with DnD5e version 4.3.9
Documentation
Detailed API documentation is available at https://yourusername.github.io/foundryvtt-dnd5e-types/
The documentation is versioned, so you can access documentation for specific versions:
- Latest: https://yourusername.github.io/foundryvtt-dnd5e-types/latest/
- Specific version: https://yourusername.github.io/foundryvtt-dnd5e-types/v1.0.0/
Installation
Requirements
- Node.js v23.11.0 or compatible (see
.nvmrc) - TypeScript 5.8.3 or later
npm
npm install --save-dev foundryvtt-dnd5e-typesyarn
yarn add --dev foundryvtt-dnd5e-typespnpm
pnpm add --save-dev foundryvtt-dnd5e-typesUsage
Add the package to your tsconfig.json file:
{
"compilerOptions": {
"types": [
"@league-of-foundry-developers/foundry-vtt-types",
"foundryvtt-dnd5e-types"
]
}
}Then you can use the types in your TypeScript code:
// Example: Access a DnD5e actor
const actor = game.actors.get("actor-id") as Game["actors"]["get"] & dnd5e.documents.Actor5e;
console.log(actor.system.attributes.ac.value);
// Example: Access a DnD5e item
const item = actor.items.get("item-id") as dnd5e.documents.Item5e;
console.log(item.system.damage.parts);
// Example: Create a new DnD5e actor sheet
class MyCustomActorSheet extends dnd5e.applications.ActorSheet5eCharacter {
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["dnd5e", "sheet", "actor", "character", "my-custom-sheet"],
width: 720,
height: 680
});
}
}
// Example: Use DnD5e utility functions
const abilityMod = dnd5e.utils.calculateAbilityModifier(14); // Returns 2Structure
The type definitions are organized into the following namespaces:
dnd5e.documents
Document classes for the DnD5e system:
Actor5e: The base actor class for DnD5e actorsItem5e: The base item class for DnD5e itemsToken5e: The token class for DnD5e tokensActiveEffect5e: The active effect class for DnD5e effectsChatMessage5e: The chat message class for DnD5e messagesCombat5e: The combat class for DnD5e combatsCombatant5e: The combatant class for DnD5e combatantsJournalEntryPage5e: The journal entry page class for DnD5e journal entries
dnd5e.data
Data models for the DnD5e system:
ActorData: Data models for DnD5e actors (CharacterData, NPCData, VehicleData)ItemData: Data models for DnD5e items (WeaponData, SpellData, etc.)
dnd5e.applications
Application classes for the DnD5e system:
ActorSheet5e: The base actor sheet class for DnD5e actorsActorSheet5eCharacter: The character actor sheet classActorSheet5eNPC: The NPC actor sheet classActorSheet5eVehicle: The vehicle actor sheet classItemSheet5e: The base item sheet class for DnD5e itemsDialog5e: The dialog class for DnD5e dialogs
dnd5e.config
Configuration data for the DnD5e system:
DND5EConfig: The configuration object for the DnD5e system
dnd5e.dice
Dice rolling utilities for the DnD5e system:
d20Roll: Roll a d20 with advantage/disadvantagedamageRoll: Roll damagehitDieRoll: Roll hit dice
dnd5e.utils
Utility functions for the DnD5e system:
calculateAbilityModifier: Calculate ability modifierscalculateProficiencyBonus: Calculate proficiency bonus- And many more utility functions
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development Setup
- Clone the repository
- Use the correct Node.js version:
nvm use(requires nvm) - Install dependencies:
npm install - Build the project:
npm run build
Code Quality Tools
This project uses several tools to ensure code quality:
ESLint: Lints TypeScript code
- Run:
npm run lint - Fix issues:
npm run lint:fix
- Run:
Prettier: Formats code consistently
- Run:
npm run format - Check formatting:
npm run format:check
- Run:
TypeDoc: Generates API documentation
- Run:
npm run docs - Output:
docs/directory - Versioned docs: Published automatically with each release to GitHub Pages
- Run:
Adding New Types
If you want to add new types or improve existing ones:
- Find the appropriate file in the
src/typesdirectory - Add or update the type definitions
- Build the project to ensure there are no errors:
npm run build - Submit a pull request using conventional commit messages
Commit Message Guidelines
This project follows Conventional Commits for commit messages. This helps with automatic versioning and changelog generation. Examples:
feat: add types for ActorSheet5eCharacter- for new features (minor version bump)fix: correct return type of getData method- for bug fixes (patch version bump)docs: update usage examples- for documentation changes (no version bump)chore: update dependencies- for maintenance tasks (no version bump)feat!: rename method to follow new convention- for breaking changes (major version bump)
Release Process
This project uses Release Please for automated releases:
- Commits to the main branch are automatically analyzed
- Release Please creates or updates a release PR that:
- Updates the version in package.json based on conventional commits
- Updates the CHANGELOG.md with all changes
- When the release PR is merged, Release Please:
- Creates a GitHub release
- Tags the release
- Publishes the package to npm
Automated Updates
This package includes a GitHub Action that automatically checks for new versions of the DnD5e system and updates the type definitions accordingly. The action runs daily and creates a pull request when a new version is detected.
You can also manually trigger the action from the Actions tab in the GitHub repository.
How it works
- The action checks the latest version of the DnD5e system from the official repository
- If a new version is detected, it downloads the source code
- It analyzes the source code to identify classes, methods, properties, etc.
- It extracts JSDoc comments and infers types from the code
- It updates the type definitions based on the analysis
- It creates a pull request with the changes
Manual Update Process
You can also run the update process manually:
# Download the latest DnD5e system
npm run download-dnd5e
# Analyze the DnD5e system
npm run analyze
# Update the type definitions
npm run update-types
# Fix any declaration issues
npm run fix-declarations
# Or run the entire process at once
npm run check-dnd5eThe automated updates help keep the type definitions in sync with the latest version of the DnD5e system, but manual review is still required to ensure accuracy.
Advanced Usage
Working with Actor Data
The DnD5e system uses a complex data structure for actors. Here's how to work with it:
// Access character data
const character = game.actors.get("character-id") as Game["actors"]["get"] & dnd5e.documents.Actor5e;
const characterData = character.system as dnd5e.data.CharacterData;
// Access ability scores
const strength = characterData.abilities.str.value;
const dexterity = characterData.abilities.dex.value;
// Access skills
const acrobatics = characterData.skills.acr.total;
const perception = characterData.skills.prc.passive;Working with Item Data
Similarly, items have different data structures based on their type:
// Access weapon data
const weapon = actor.items.get("weapon-id") as dnd5e.documents.Item5e;
const weaponData = weapon.system as dnd5e.data.WeaponData;
// Access spell data
const spell = actor.items.get("spell-id") as dnd5e.documents.Item5e;
const spellData = spell.system as dnd5e.data.SpellData;Extending DnD5e Classes
You can extend the DnD5e classes to create your own custom functionality:
class MyCustomActor extends dnd5e.documents.Actor5e {
// Add custom methods
calculateCustomStat() {
return this.system.abilities.str.value + this.system.abilities.con.value;
}
}
class MyCustomSheet extends dnd5e.applications.ActorSheet5eCharacter {
// Override methods
getData() {
const data = super.getData();
// Add custom data
data.customData = "Custom value";
return data;
}
}Troubleshooting
Type Errors
If you encounter type errors, make sure you're using the correct type assertions:
// Incorrect
const actor = game.actors.get("actor-id"); // Type is Actor
// Correct
const actor = game.actors.get("actor-id") as Game["actors"]["get"] & dnd5e.documents.Actor5e;Missing Properties
If you encounter missing properties, it might be because:
- The property is new in a version of DnD5e that's not yet supported
- The property is custom added by a module
- The property is internal and not exposed in the type definitions
You can use type assertions to work around these issues:
// Access a property that's not in the type definitions
const customValue = (actor.system as any).customProperty;Versioning and Compatibility
Version Scheme
This package follows Semantic Versioning:
- Major version (x.0.0): Breaking changes that require updates to your code
- Minor version (0.x.0): New features or types added in a backward-compatible manner
- Patch version (0.0.x): Bug fixes and minor improvements
Automated Versioning
The package version is automatically updated using Release Please based on Conventional Commits:
feat:commits trigger a minor version bumpfix:commits trigger a patch version bumpfeat!:orfix!:commits trigger a major version bump
DnD5e Compatibility
Each release of this package is compatible with a specific version of the DnD5e system. The compatible DnD5e version is noted:
- In the README (see the badge at the top)
- In the package description on npm
- In the GitHub release notes
- In the
version.jsonfile in the repository
When a new version of DnD5e is released, this package will be automatically updated to support it, typically within a few days. These updates are made with feat: commits, which trigger a minor version bump.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Foundry VTT
- League of Extraordinary Foundry VTT Developers
- foundry-vtt-types
- DnD5e System
- Release Please for automated releases