运行时未定义Typescript模块

Typescript Module not defined at runtime

本文关键字:模块 Typescript 未定义 运行时      更新时间:2023-09-26

为什么我在运行时得到错误:TSDummyProject is not defined

数据实体.d.ts:

declare module TSDummyProject.Models {
    export class Part {
        ID: number;
        PartName: string; 
        ...
    }
}

manager.ts:

/// <reference path="dbentities.d.ts"/>
class PartManagerController {
    private curPart: TSDummyProject.Models.Part;
    ...
    someFunction(){
        // error: TSDummyProject is not defined 
        this.curPart = new TSDummyProject.Models.Part(); 
    }
}

如果在typescript中"声明"某些内容,它不会生成任何javascript。这是typescript的意思是说"这是在其他地方定义的,例如JavaScript代码。假设它在那里。"

在你的情况下,它不是。也许您打算用typescript编写代码,或者忘记在页面中包含前面提到的JavaScript