[SOLVED] Optional Chaining causes code completion fail

Hello, this is mostly a cosmetical error, but optional chaining(?.) causes editor to stop providing any useful information. Also while using generator functions same thing happens. Is there any workaround?

Hi @SiyahaS,

Where exactly do you put that code? Can you provide an example?

Whatever is inside script prototype methods won’t be parsed by the editor when searching for attributes, so that is quite safe.

I wasn’t talking about editor attributes, but the attributes i have defined in code or the general suggestions about playcanvas types(script, element etc).

// initialize code called once per entity
Board.prototype.initialize = function() {
    this.tileContainer = new pc.Entity("Tiles");
    this.tileContainer.setLocalPosition(0, 0, -1);
    this.entity.addChild(this.tileContainer);

    this.gamePieceContainer = new pc.Entity("GamePieces");
    this.entity.addChild(this.gamePieceContainer);

    this.clickedTileBomb = undefined;
    this.targetTileBomb = undefined;
    this.allTiles = new Array(this.dimensions.x * this.dimensions.y);
    this.allGamePieces = new Array(this.dimensions.x * this.dimensions.y);
    this.clickedTile = undefined;
    this.targetTile = undefined;
    this.playerInputEnabled = true;
    this.scoreMultiplier = 0;
};

Here you can find it in line594(optional chaining branch)
project link

I could not replicate the same behaviour in a new script.

I found that after using optional chaining for once other declerations have type of undefined. I’m guessing it breaks the js parser.

Ah got it, not runtime errors but in the code editor. That is expected at the moment since the code editor fully supports only ES5 JS.

You can get partial ES6 support by adding the following directive in the first line of any script:

/*jshint esversion: 6 */

But this supports only basic ES6 syntax like const, let, arrow functions. Async/await isn’t supported.

Here you can find a workaround a user posted to improve on that:

2 Likes