DefinitelyTyped has a Dojo solution which uses named modules and may work with legacy Dojo and explicit typing. But these declarations do not facilitate TypeScript import
, since there are no anonymous modules. It seems to be a more exhaustive and consistent version of schungx/Dojo-TypeScript, but without the declared modules which make import
work.
schungx/Dojo-TypeScript does not allow for 'extends' of an import
Dijit but provides both named and anonymous declarations.
Brian Forbes provides a dijit.d.ts
definition which is good at consuming dijits
from TypeScript. His solution is available here. It works perfectly well with import
, since it uses anonymous module declarations, but still does not allow for TypeScript inheritance (even the incompatible type).
The following code allows me to develop TypeScript wijits that extend ContentPane
that actually work (despite the inheritance compatibility).
declare module "dijit/layout/ContentPane"
{
class w extends dijit._Widget {
addChild(w: dijit._WidgetBase, index?: number);
}
export = w;
}
It extends the _Widget class defined in schungx/Dojo-TypeScript and tricks tsc
into thinking the ContentPane
is a TypeScript class.
This is what extends means (d
is derived class, b
is base class):
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
The derived class gets all base properties, including prototype. But I've been warned several times that this is unsafe.
My questions:
Is it really unsafe?
Is there a reasonable approach to making this safe? I don't believe my Typescript Hack to extend ContentPane is reasonable.