为什么我的TypeScript声明类抛出Not Declared异常?

时间:2013-03-05 10:58:24

标签: asp.net-mvc typescript

我有以下TypeScript模块,为简洁起见,删除了不必要的绒毛:

/// <reference path="jquery.d.ts" />
module SelectionOtherInputs {
    export class SelectionOtherInputDescriptor {
        constructor(public selectionId: string, public otherKey: any, public otherInputElementId: string) { }
    }
    export class SelectionOtherInputHelper {

        selectionsWithOther: { [selectionKey: string]: SelectionOtherInputDescriptor; } = {};

        getAllSelectionOthers() {
            $("[" + ATT_SELECTION_OTHER_FOR + "]").each(function () {
                var key = $(this).attr(ATT_DATA_SELECTION_OTHER_KEY);
                var desc = new SelectionOtherInputDescriptor("0", key, $(this).attr("id"));
                this.selectionsWithOther[key] = desc;
            });
        }
    }
}

然后我尝试在小型演示页面中使用SelectionOtherInputHelper类,如下所示:

@section scripts
{
    <script src="~/Scripts/TypeScript/OtherInput.js"></script>
    <script>
        var otherManager = new SelectionOtherInputHelper();
        otherManager.getAllSelectionOthers();
    </script>
}

正在渲染`scripts'部分和jQuery,但我仍然得到了

  

未捕获的ReferenceError:未定义SelectionOtherInputHelper

var otherManager = new SelectionOtherInputHelper()来电时出现

错误。我还需要做些什么来正确导入和使用这个类?

1 个答案:

答案 0 :(得分:1)

我想你忘了这个模块:

@section scripts
{
    <script src="~/Scripts/TypeScript/OtherInput.js"></script>
    <script>
        var otherManager = new SelectionOtherInputs.SelectionOtherInputHelper();
        otherManager.getAllSelectionOthers();
    </script>
}