Typescript types - Sprite extends GameObject but still errors

When using Phaser 3 with typescript I want to call

Phaser.Actions.Call(this.enemies.getChildren(), function (this: MainScene, enemy: Phaser.GameObjects.Sprite) {

But the callback of Actions call errors because it needs Phaser.GameObjects.GameObject, even dough Phaser.GameObjects.Sprite extends Phaser.GameObjects.GameObject what am I missing.

The enemies array is a group

this.enemies = this.add.group(undefined, {
            key: "enemy",
            repeat: 5,
            setXY: {
                x: 90,
                y: 100,
                stepX: 80,
                stepY: 20,
            }
        });

:wave:

What’s the full code of the callback function and what’s the error message?


This is the error

And this is the entire callback

Phaser.Actions.Call(this.enemies.getChildren(), function (this: MainScene, enemy: Phaser.GameObjects.Sprite) {
                enemy.flipX = true;
                // speed and direction
                const direction = Math.random() < 0.5 ? 1 : -1;
                const speed = this.enemyMinSpeed + Math.random() * (this.enemyMaxSpeed - this.enemyMinSpeed);
                enemy.velocity = direction * speed;
        }, this);

I think you can use a type assertion instead:

Phaser.Actions.Call(
  this.enemies.getChildren(),
  function (this: MainScene, enemy: Phaser.GameObjects.GameObject) {
    // […]
    (enemy as Phaser.GameObjects.Sprite).velocity = direction * speed;
  },
  this
);