tengo un error Only a void function can be called with the 'new' keyword. cuando intento declarar una instancia de una función.
Busque en google pero este mensaje aparece en varios errores distintos.
Funcion:
export default function Default() {
let object: objeto;
let $el: any = {};
let config: any = {};
let color: any = {};
let maskTitle: (text: string, datamap: any[]) => string = function(value) { return value };
object.render = function(valuesLeyend, dataMap: any[]) {
let legend = $el.selectAll(".legend")
.data(valuesLeyend.slice())
.enter().append("div")
.attr("class", "legend g-row")
.style("font-family", "Roboto")
.style('margin', '2px');
legend.append("div")
.style("width", "15px")
.style("height", "15px")
.style("background", color);
legend.append("div")
.style("font-size", config.fontSize+"px")
.style("padding", "0 10px")
.style("width", "90%")
.style("overflow", "hidden")
.style("text-overflow", "ellipsis")
.style("white-space", "nowrap")
.html((d) =>{return maskTitle(d,dataMap)});
return object;
}
object.$el = function(value){
if (!arguments.length) return $el;
$el = value;
return object;
};
object.config = function(value){
if (!arguments.length) return config;
config = value;
return object;
};
object.color = function(value){
if (!arguments.length) return color;
color = value;
return object;
};
object.maskTitle = function(value){
if (!arguments.length) return maskTitle;
maskTitle = value;
return object;
};
return object;
}
interface objeto {
render: (value, datamap: any[]) => any;
$el: (value) => any;
config: (value) => any;
color: (value) => any;
maskTitle: (value) => any;
}
La función tiene que retornar obligatoriamente para que funcione como fue pensada originalmente en JS. Actualmente estoy pasando a typeScript y si quiero respetar tal cual como esta en js no me queda otra que preservar la funcion pero me encontre con este error que parece no admitir returns.