4

バックグラウンド

現在、私が働いている場所では、dojo.requires を使用して、各クラスで使用する必要なすべてのクラスをインポートしています。しかし、Dojo 2.0 では dojo.require を取り除き、amd の require スタイル ( http://livedocs.dojotoolkit.org/releasenotes/migration-2.0 )に移行しています。

require(["dijit/form/Button", "dojox/layout/ContentPane", ...], 
   function(Button, ContentPane, ...){
    // CODE HERE
});

現在、独自の .d.ts ファイルで次のように定義された dojo/dijit クラスがあります。

module dijit.form{
    export class Button extends dijit.form._FormWidget {
        showLabel : bool;
        _onClick (e:any) : any;
        _onButtonClick (e:any) : any;
        _setShowLabelAttr (val:any) : any;
        _clicked (e:any) : any;
        setLabel (content:String) : any;
        _setLabelAttr (content:String) : any;
        _setIconClassAttr (val:String) : any;
    }
}

これにより、これらのクラスを次のように拡張できます。

class CustomButton extends dijit.form.Button {}

問題

typescript で Dojo 2.0 (amd) スタイルの要件を生成し、次のような処理を実行できるようにしたいと考えています。

import Button = module("dijit/form/Button")
class CustomButton extends Button {}

これは、次のようなものにコンパイルされることを望んでいました。

define(["require", "exports", "dijit/form/Button"], function(require, exports, Button)    
{
    ///....Generated class    
})

ただし、インポートはクラスではなくモジュールに対してのみ機能するため、これは機能しません。次のようなエラーが表示されます。

The name '"dijit/form/Button"' does not exist in the current scope
A module cannot be aliased to a non-module type

また、次のような dijit クラスを定義しようとしました。

declare module "dijit/form" {
    export class Button....
}

私たちがやろうとしていることを達成する方法はありますか?

ありがとう

4

1 に答える 1

2

AMDモジュールでは、モジュールはファイルに相当するため、次の名前のファイルがある場合:

dijit.forms.tsまたはdijit.forms.d.ts

を使用してロードできます

import forms = module("dijit.forms");

var button = new forms.Button();

ファイルがモジュールであるため、AMD アプリケーションの定義ファイル内でモジュールを宣言する必要はありません。

于 2012-11-25T16:22:30.237 に答える