In our game we use typescript, pixi.js, vscode, eslint.
We have a dictionary of image files like this
export function getAllImages(): {name: string, extension: string}[] {
return [
{name: 'tile_lumber', extension: '.svg'},
{name: 'tile_brick', extension: '.svg'},
....
]
}
which is loaded like this
export function loadImages() {
for(const img of getAllImages()) {
PIXI.Loader.shared.add(img.name, getImagePath(img.name + img.extension), { crossOrigin: true })
}
PIXI.Loader.shared
.on('progress', loadProgressHandler)
.load(assetsFinishedLoading)
}
When we call the item we write it like this
export function getBannerForPlayer(playerColor: PlayerColors): PIXI.Texture {
switch(playerColor) {
case PlayerColors.Bronze: return PIXI.Loader.shared.resources.banner_bronze.texture
case PlayerColors.Silver: return PIXI.Loader.shared.resources.banner_silver.texture
case PlayerColors.Gold: return PIXI.Loader.shared.resources.banner_goldf.texture
....
}
}
This code does not give an error in the compiler even though there is no texture called banner_goldf it should be banner_gold. We accidentally pushed this code and it has caused a bug in the game.
Ideally vscode, tsc or something else should be showing error for cases like this. How can we make sure that it shows error?