0

I'm using draw2d on angular2 (draw2d-wrapper). I'm trying extend a class from them.

export class Table extends (draw2d.shape.layout.VerticalLayout as { new(): any }) {
    static NAME: "Table";
    /*Some code*/
}

on my code when I do var t = new Table();

the t.NAME property came as "draw2d.shape.layout.VerticalLayout".

Can I override this JavaScript property in a angular2 typescript code?

Philip
  • 3,486
  • 1
  • 24
  • 37

1 Answers1

0

Since you are trying to access the property on your table instance, it's not really a static property. Simplifying your example, this works:

class VerticalLayout {
  NAME = "VerticalLayout";
}

class Table extends VerticalLayout  {  
  NAME = "Table";
}

new Table().NAME; // Table

I would expect the same to work for deriving from draw2d.shape.layout.VerticalLayout

Titian Cernicova-Dragomir
  • 230,986
  • 31
  • 415
  • 357
  • That solves partially the problem, now the problem is in a method is a superclass of (draw2d.shape.layout.VerticalLayout) that uses the eval method to create a new instance of the object `var o = eval("new "+element.type+"()");` when the name is "draw2d....." i have no error but the method that i override on my sub class is not called. When element.type is "Table" i get this error message `"Unable to instantiate figure type 'Tabela' with id…rshal by draw2d.io.json.Reader. Skipping figure.."]` – Joao Silva Sep 08 '17 at 16:16