Skip to content

Automatic Type-Safety

Dill Pixel is designed to provide a highly productive and type-safe development experience out of the box. The framework automatically generates TypeScript definition files based on your project’s configuration and assets, giving you powerful IntelliSense and preventing common runtime errors.

This happens in two key areas: Application-level types and Asset-level types.

The framework inspects your dill-pixel.config.ts and src/scenes directory to understand the structure of your application. It then generates a src/types/dill-pixel-app.d.ts file that uses TypeScript’s module augmentation to override core framework types.

This provides you with autocompletion for:

  • Scene IDs
  • Action names and contexts
  • Plugin and Storage Adapter IDs
  • Your custom Application class methods and properties.

When you define scenes in src/scenes, their IDs are automatically added to the AppScenes type. This means you get full autocompletion when loading or transitioning to a scene.

// Assuming you have a scene in `src/scenes/MainMenu.ts`
// with `export const id = 'main-menu';`
// ✅ Correct: You'll get 'main-menu' in your IntelliSense list.
this.app.scenes.loadScene('main-menu');
// ❌ Incorrect: TypeScript will flag this as an error.
this.app.scenes.loadScene('non-existent-scene');

Actions and contexts defined in your dill-pixel.config.ts are used to generate AppActions and AppContexts types.

export const contexts = defineContexts(['game', 'menu']);
export const actions = defineActions(contexts, {
jump: { context: ['game'] },
open_menu: { context: '*' },
});

When you specify a custom application class in your config, the framework ensures that this.app is correctly typed to your class everywhere, giving you access to any custom methods you’ve added.

import { Application } from 'dill-pixel';
export class MyApplication extends Application {
public saveGame() {
console.log('Game saved!');
}
}

Similarly, the framework watches your asset manifest (typically public/assets/assets.json) and generates a src/types/dill-pixel-assets.d.ts file. This file contains types for all your asset aliases.

This gives you autocompletion when loading, retrieving, and using assets like textures, audio, and spritesheets.

All asset aliases from your manifest are available for type-safe loading and retrieval.

The types flow through the entire framework, providing safety and autocompletion when using assets with other components.

// From within a Container or Scene
// ✅ Correct: You get autocompletion for texture aliases here.
const player = this.add.sprite({asset: 'player-sprite'});