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

时间:2023-02-04 17:02:17

I have the following TypeScript module, unnecessary fluff removed for brevity:

我有以下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;
            });
        }
    }
}

Then I try and use the SelectionOtherInputHelper class in a small demo page as follows:

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

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

The `scripts' section is being rendered, and jQuery, but I still get a

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

Uncaught ReferenceError: SelectionOtherInputHelper is not defined

未捕获的ReferenceError:未定义SelectionOtherInputHelper

error on the var otherManager = new SelectionOtherInputHelper() call. What else must I do to properly import and use this class?

var otherManager = new SelectionOtherInputHelper()调用错误。我还需要做些什么来正确导入和使用这个类?

1 个解决方案

#1


1  

I think you forgot the module:

我想你忘了这个模块:

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

#1


1  

I think you forgot the module:

我想你忘了这个模块:

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