javascriptnode.jstypescriptaway3d

TypeScript error TS2082 and TS2087 assigning Away3D canvas to a var


I am new to TypeScript. I am creating an Away3D scene, that dynamically creates a canvas element. I would like to append that element to a container.

The code works, but I get the following compiling errors:

error TS2082: Supplied parameters do not match any signature of all target: Type 'examples.MinimalScene' is missing property 'nodeType' from type 'Node'.

and

error TS2087: Could not select overload for 'call' expression.

I know it is in my onload function at the bottom trying to set a variable to the new function call.

I just don't know where to put the property 'nodeType' ??

Any help would be very appreciated.

Here is my code:

module examples
{
    export class MinimalScene
    {
        private _view:away.containers.View = new away.containers.View(new away.render.DefaultRenderer());
        private _cubeGeometry:away.primitives.CubeGeometry = new away.primitives.CubeGeometry(250, 250, 250);
        private _cubeMesh:away.entities.Mesh = new away.entities.Mesh(this._cubeGeometry); 

        constructor(private away3DContainer)
        {
            this._view.width = this.away3DContainer.offsetWidth;
            this._view.height = this.away3DContainer.offsetHeight;
            this._view.scene.addChild(this._cubeMesh);
            this._view.render();
        }
    }
}

window.onload = function ()
{
    var awayContainer = document.getElementById('away3DContainer');
    var awayCanvas = new examples.MinimalScene(awayContainer);
    awayContainer.appendChild(awayCanvas);
}

Solution

  • Assuming the error is in the following line :

    var awayContainer = document.getElementById('away3DContainer');
    var awayCanvas = new examples.MinimalScene(awayContainer);
    awayContainer.appendChild(awayCanvas); // Error here
    

    It is because the type MinimalScene is not compatible with Node which is the expected for appendChild

    Quick fix : use any:

    var awayContainer = document.getElementById('away3DContainer');
    var awayCanvas:any = new examples.MinimalScene(awayContainer); // Quick fix
    awayContainer.appendChild(awayCanvas); // no Error
    

    It will fix the compile error, but I suspect that your appendChild is wrong.