question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AddChild in DisplayObject doesn't allow spreading anymore

See original GitHub issue

Hello, after updating to 6.2.0 I’m experiencing this behavior.

Expected Behavior

When using a spread operator to add to a DisplayObject like const containers = [new Container(), new Container()] a.stage.addChild(...containers) I expect no ts issues

Current Behavior

Currently getting A spread argument must either have a tuple type or be passed to a rest parameter.ts(2556)

Possible Solution

Possibly it is due to this change in addChild

addChild<T extends DisplayObject>(…children: [T, …DisplayObject[]]): T; (6.2.0) addChild<T extends DisplayObject[]>(…children: T): T[0]; (6.1.3)

Steps to Reproduce

Environment

  • pixi.js version: 6.2.0
  • OS & Version: Mac OS Big Sur

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bigtimebuddycommented, Nov 2, 2021

This is the workaround for the type error.

const containers: [Container, Container] = [new Container(), new Container()];
app.stage.addChild(...containers);

In this case, because we tweaked the typing slightly, you need to be explicit about the type for containers.

0reactions
MercurialUroboroscommented, Nov 2, 2021

Thanks, I’m aware of the workarounds, I will be waiting for something more succinct.

This is the workaround for the type error.

const containers: [Container, Container] = [new Container(), new Container()];
app.stage.addChild(...containers);

In this case, because we tweaked the typing slightly, you need to be explicit about the type for containers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

addChild(): How can I know when a DisplayObject is actually ...
I've got a large (4096x4096) image loaded into memory, but when I try to use addChild, there is a long delay before it...
Read more >
Quick Way to Set Props on a New Instance - gskinner blog
A quick way to set multiple properties on new instances, and a related AS3 feature request.
Read more >
DisplayObjectContainer - Adobe ActionScript® 3 (AS3 ) API ...
Calling the new DisplayObjectContainer() constructor throws an ArgumentError exception. DisplayObjectContainer. addChild(child:DisplayObject):DisplayObject.
Read more >
Flash - senocular.com
Loader is a Sprite-like display object which, like Sprite, has no timeline, but is designed specifically to facilitate the loading of external display ......
Read more >
Phaser.Rope - 2.6.1 - Learn
Working in radians is slightly faster as it doesn't have to perform any ... The lifespan allows you to give a Game Object...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found