Skip to content
This repository was archived by the owner on Sep 26, 2019. It is now read-only.
This repository was archived by the owner on Sep 26, 2019. It is now read-only.

Support the ability to emit certain types as interfaces with construct signatures (instead of classes) #82

Open
@jumpinjackie

Description

@jumpinjackie

Currently if you take a random Cesium sandcastle example (for example):

// Add several billboards based on the above image in the atlas.
    viewer.entities.add({
        position : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
        billboard : {
            image : '../images/whiteShapes.png',
            imageSubRegion : new Cesium.BoundingRectangle(49, 43, 18, 18),
            color : Cesium.Color.LIME
        }
    });
    viewer.entities.add({
        position : Cesium.Cartesian3.fromDegrees(-84.0, 39.0),
        billboard : {
            image : '../images/whiteShapes.png',
            imageSubRegion : new Cesium.BoundingRectangle(61, 23, 18, 18),
            color : new Cesium.Color(0, 0.5, 1.0, 1.0)
        }
    });

It is compiler errors galore on the objects being added. This is because the API documentation states that these are meant to be Cesium.Entity instances. But because Cesium.Entity is a class, it is not assignable from an object that happens to have the same "shape" as it.

From this I strongly suspect that Entity should really be a TS interface, but have a declared var of the same name that defines the constructor.

So where we currently have this

class Entity {
    constructor(...);
    id: string;
    name: string;
    ...
    addProperty(propertyName: string);
}

The plugin should have the ability for us to say that Entity should be an interface, that should then generate something like this:

interface Entity {
    id: string;
    name: string;
    ...
    addProperty(propertyName: string);
}
declare const Entity: {
    new (...): Entity
}

With this pattern (and a switch that allows all members of the class-now-interface to be optional), it should allow for the above sandcastle example to be legal.

This is how TypeScript defines built-ins like Object, String, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions