Skip to content

TypeScript compiler error when adding a layer to a layer #5459

@PhaserEditor2D

Description

@PhaserEditor2D

Version

  • Phaser Version: 3.50.0
  • Operating system: Linux
  • TypeScript: 4.0.5

Description

The Phaser.GameObjects.Layer class doesn't extend Phaser.GameObjects.GameObject and it creates TypeScript compiler errors.

Example Test Code

class DemoLayer extends Phaser.Scene {

	create() {

		const layer1 = this.add.layer();

		const layer2 = this.add.layer();

		layer1.add(layer2); // error, GameObject expected

		this.sys.displayList.add(layer1); // error, GameObject expected

		this.add.existing(layer1); // error, GameObject expected
	}
}

Additional Information

You can test this project:

LayerCompilerError.zip

Unzip it and run:

$ cd LayerCompilerError
$ tsc

You will get the following errors:

main.ts:9:14 - error TS2345: Argument of type 'Layer' is not assignable to parameter of type 'GameObject'.
  Type 'Layer' is missing the following properties from type 'GameObject': parentContainer, tabIndex, input, body, and 14 more.

9  	layer1.add(layer2);
   	           ~~~~~~

main.ts:11:28 - error TS2345: Argument of type 'Layer' is not assignable to parameter of type 'GameObject'.

11  	this.sys.displayList.add(layer1);
    	                         ~~~~~~

main.ts:13:21 - error TS2345: Argument of type 'Layer' is not assignable to parameter of type 'GameObject'.

13  	this.add.existing(layer1);
    	                  ~~~~~~


Found 3 errors.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions