Typescript,类没有定义

Mar*_* G. 8 javascript typescript

我搜索过,我找到的答案对我没有帮助.

我在Typescript中创建了一个类,并希望通过它将其导入另一个Typescript-File

import '../EventDTO';
Run Code Online (Sandbox Code Playgroud)

比我查看转换后的文件(main.js),我的所有打字稿文件都转换为.在那里,还有我写过的课程,但是当我想在我的文件中使用它时:

eventList[i] = new EventDTO(data[i].id);
Run Code Online (Sandbox Code Playgroud)

我在浏览器中遇到此错误:

未捕获的ReferenceError:未定义EventDTO

EventDTO课程:

class EventDTO{

    id: number;

    constructor(_id: number){
            this.id = _id;
    }

    getId(){
        return this.id;
    }
Run Code Online (Sandbox Code Playgroud)

那么,我该怎么做呢?

Rad*_*ler 13

您需要添加export关键字

export class EventDTO{

    id: number;

    constructor(_id: number){
            this.id = _id;
    }

    getId(){
        return this.id;
    }
Run Code Online (Sandbox Code Playgroud)