GraphObject.make breaking signature changes? v1.8.2 > 2.0.x

We used to create diagrams by passing an HTMLDivElement to graphObject.make, like so:

if (this.container instanceof HTMLDivElement) {
    this.diagram = this.make(
        go.Diagram,
       this.container,
       diagramConfig
    );
}

Since updating to GoJS v2, TypeScript is complaining that an argument of type HTMLDivElement can’t be used. However, looking at the minified function in dev tools I see this line:

“string” == typeof e ? t.Ia = d.document.getElementById(e) : e instanceof HTMLDivElement ? t.Ia = e : b("No DIV or DIV id supplied: " + e)

… which suggests that it would still accept a DOM element rather than an ID selector.

So is the signature for graphObject.make wrong? Or is that clause about using a supplied HTMLDivElement just a hang-over from the previous, now-removed, functionality?

Using TypeScript 3.3.3 at our end.

No, that functionality is definitely still needed and implemented. It’s probably a TypeScript declaration problem. I’ll look into it.

Here’s the output from TS:

Argument of type ‘HTMLDivElement’ is not assignable to parameter of type ‘string | Binding | EnumValue | PanelLayout | (Partial<Diagram> & { [p: string]: any; } & DiagramEventsInterface & { Changed?: ChangedEventHandler | undefined; ModelChanged?: ChangedEventHandler | undefined; }) | (string | … 3 more … | (Partial<…> & … 2 more … & { …; }))[]’.

Type ‘HTMLDivElement’ is not assignable to type ‘Partial<Diagram> & { [p: string]: any; } & DiagramEventsInterface & { Changed?: ChangedEventHandler | undefined; ModelChanged?: ChangedEventHandler | undefined; }’.

Type ‘HTMLDivElement’ is not assignable to type ‘Partial<Diagram>’.

Types of property ‘scroll’ are incompatible.

Type ‘{ (options?: ScrollToOptions | undefined): void; (x: number, y: number): void; }’ is not assignable to type ‘(unit: “line” | “pixel” | “page” | “document”, dir: “left” | “right” | “up” | “down”, dist?: number | undefined) => void’.

Types of parameters ‘options’ and ‘unit’ are incompatible.

Type ‘“line” | “pixel” | “page” | “document”’ is not assignable to type ‘ScrollToOptions | undefined’.

Type ‘“line”’ is not assignable to type ‘ScrollToOptions | undefined’.

That HTMLDivElement type seems to have been lost in the very complicated signature that GraphObject.make has. We’ll add it back. You can do it yourself in your copy of go.d.ts.

    static make<CT extends ConstructorType<CT>>(cls: CT, ...initializers: Array<string | HTMLDivElement | (Partial<InstanceType<CT>> & {
        [p: string]: any;
    } & (InstanceType<CT> extends Diagram ? DiagramEventsInterface & {
        Changed?: ChangedEventHandler;
        ModelChanged?: ChangedEventHandler;
    } : {})) | (InstanceType<CT> extends GraphObject ? Binding : never) | (InstanceType<CT> extends Panel ? (GraphObject | RowColumnDefinition | PanelLayout) : never) | (InstanceType<CT> extends RowColumnDefinition ? Binding : never) | (InstanceType<CT> extends Geometry ? PathFigure : never) | (InstanceType<CT> extends PathFigure ? PathSegment : never) | EnumValue | Array<string | (Partial<InstanceType<CT>> & {
        [p: string]: any;
    } & (InstanceType<CT> extends Diagram ? DiagramEventsInterface & {
        Changed?: ChangedEventHandler;
        ModelChanged?: ChangedEventHandler;
    } : {})) | (InstanceType<CT> extends GraphObject ? Binding : never) | (InstanceType<CT> extends Panel ? (GraphObject | RowColumnDefinition | PanelLayout) : never) | (InstanceType<CT> extends RowColumnDefinition ? Binding : never) | (InstanceType<CT> extends Geometry ? PathFigure : never) | (InstanceType<CT> extends PathFigure ? PathSegment : never) | EnumValue>>): InstanceType<CT>;
. .

Thanks for the quick solution, I’ll do that.

My product owner is asking what your expected bug resolution time is - do you have any info I could pass on?

I have edited my previous reply with the complete declaration from the go.d.ts file that now includes HTMLDivElement. I hope that works for you.

Hmmm, maybe we should work on adding some types that would make this declaration more readable…

We try to avoid putting out releases more than once a week, so I would say next week.

Brilliant thanks for the feedback.

Yeah the signature for graphObject.make is pretty… Extreme. It’s funny that it returns {Object} though. :D

No, in your case it’s returning go.Diagram.

    . . . : InstanceType<CT>;

OK, I believe this will be fixed in 2.0.4.