# createFromObjects classType and typescript extends

**URL:** <https://phaser.discourse.group/t/createfromobjects-classtype-and-typescript-extends/10239>\
**Category:** Phaser 3\
**Created:** [September 12, 2021, 10:48pm UTC](https://phaser.discourse.group/t/createfromobjects-classtype-and-typescript-extends/10239 "2021-09-12T22:48:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![danfoster](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/danfoster/32/5580_2.png) [@danfoster](https://phaser.discourse.group/u/danfoster)\
**Post date:** [September 12, 2021, 10:48pm UTC](https://phaser.discourse.group/t/createfromobjects-classtype-and-typescript-extends/10239/1 "2021-09-12T22:48:56Z")

</div>

Hi,

I want to use [`CreateFromObjects`](https://photonstorm.github.io/phaser3-docs/Phaser.Tilemaps.Tilemap.html#createFromObjects__anchor) to create Players, which are custom classes that extend the `Phase.GameObjects.Sprite` object.

I thought I could achieve this using the the [`classType`](https://photonstorm.github.io/phaser3-docs/Phaser.Types.Tilemaps.html#.CreateFromObjectLayerConfig) property. But I get the following error:

```javascript
TS2740: Type 'typeof Player' is missing the following properties from type 'GameObject': scene, displayList, type, state, and 42 more.

```

( I’m using typescript )

Here is example code:

```javascript
import * as Phaser from 'phaser';

class Player extends Phaser.GameObjects.Sprite {
    constructor(scene: Phaser.Scene, x: number, y: number) {
        super(scene, x, y, "player_blue");
    }
}

const sceneConfig: Phaser.Types.Scenes.SettingsConfig = {
    active: false,
    visible: false,
    key: 'Game',
};

export class GameScene extends Phaser.Scene {
    private player: Player;

    constructor() {
        super(sceneConfig);
    }

    public preload() {
        this.load.image("tiles_board", "/assets/tilesets/board.png");
        this.load.image("player_blue", "/assets/sprites/player_blue.png"); 
        this.load.tilemapTiledJSON('map_test', '/assets/maps/test.json');
    }

    public create() {

        const map = this.make.tilemap({ key: 'map_test' });
        const tiles = map.addTilesetImage("tiles_board");
        map.createLayer('main', tiles);

        const players: Player[] = <Player[]>map.createFromObjects('players', {
            name: 'player1',
            classType: Player
        });
        this.player = players[0];

     

    }
   
}

```

I feel like I’m missing something fundamental about how typescript inheritance works, but I can’t see what. Could anyone point out my mistake?

Thanks!

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [September 12, 2021, 10:55pm UTC](https://phaser.discourse.group/t/createfromobjects-classtype-and-typescript-extends/10239/2 "2021-09-12T22:55:32Z")

</div>

That looks correct. Can you try `{ classType: Phaser.GameObjects.Sprite }` to see what happens?

---

<div class="post-metadata">

**Author:** ![danfoster](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/danfoster/32/5580_2.png) [@danfoster](https://phaser.discourse.group/u/danfoster)\
**Post date:** [September 13, 2021, 8:20am UTC](https://phaser.discourse.group/t/createfromobjects-classtype-and-typescript-extends/10239/3 "2021-09-13T08:20:29Z")

</div>

Good thinking, I get a similar error when using that:

```javascript
TS2740: Type 'typeof Sprite' is missing the following properties from type 'GameObject': scene, displayList, type, state, and 42 more.

```

Does that suggest I’ve got the syntax for setting the property wrong? For completeness, the call to `createFromObjects` now looks like this:

```javascript
  const players: Player[] = <Player[]>map.createFromObjects('players', {
            name: 'player1',
            classType: Phaser.GameObjects.Sprite
        });

```

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [September 13, 2021, 1:49pm UTC](https://phaser.discourse.group/t/createfromobjects-classtype-and-typescript-extends/10239/4 "2021-09-13T13:49:39Z")

</div>

This may have been a problem with Phaser’s types. You could update Phaser or just ignore the error.

---

<div class="post-metadata">

**Author:** ![danfoster](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/danfoster/32/5580_2.png) [@danfoster](https://phaser.discourse.group/u/danfoster)\
**Post date:** [September 13, 2021, 3:11pm UTC](https://phaser.discourse.group/t/createfromobjects-classtype-and-typescript-extends/10239/5 "2021-09-13T15:11:08Z")

</div>

Ah ha! I just learnt that `@ts-ignore` exists. Ignore the error on that line allows my code to run.  
So, as you say, it’s more likely a problem with Phaser’s types. This is on latest release (v3.55.2).

Looks like supporting `classTypes` in createFromObjects only came in v3.50.0 (Dec 2020): [Support classType in CreateFromObjects/Tiles · Issue #4613 · photonstorm/phaser · GitHub](https://github.com/photonstorm/phaser/issues/4613) .

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![top-kat](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/top-kat/32/7557_2.png) [@top-kat](https://phaser.discourse.group/u/top-kat)\
**Post date:** [April 14, 2023, 2:24am UTC](https://phaser.discourse.group/t/createfromobjects-classtype-and-typescript-extends/10239/6 "2023-04-14T02:24:29Z")

</div>

Another “hack”: `{ classType: Phaser.GameObjects.Player as any }`

The as any helps a lot because there is a lot of caveat with phaser and typescript ^^

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [April 14, 2023, 2:25am UTC](https://phaser.discourse.group/t/createfromobjects-classtype-and-typescript-extends/10239/7 "2023-04-14T02:25:30Z")

</div>

I think this problem is fixed in Phaser v3.60.
