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:

  • Did the folks who advised you that this approach was unsafe explain why they thought so? – Robert Harvey Feb 24 '16 at 17:18
  • The gist of the concern was keeping it compatible with future version of the framework and making sure the component would work in various scenarios. I got it working and so I used it. – Corey Alix Feb 25 '16 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.