简体   繁体   English

如何在Typescript中导入枚举

[英]How to import enum in Typescript

I have the following two files: bag.js 我有以下两个文件:bag.js

import {BagType} from "./bagType"     //this line of code gives an error message: bagtype.ts is not a modul
import {Present} from "./present";

export class Bag {

    private maxWeight: number;
    private bagType: BagType;
    private presents: Array<Present> = new Array<Present>();

    constructor(maxWeight: number, bagType: BagType) {
        this.maxWeight = maxWeight;
        this.bagType = bagType;
    }

    public addPresent(present: Present){
        this.presents.push(present);
    }
}

and bagType.js 和bagType.js

enum BagType {

    Canvas,
    Paper
}

My question is the next: How can I import the enum BagType to the Bag class? 我的问题是下一个:如何将枚举BagType导入Bag类?

I tried it and it worked with: 我尝试了它,它与:

export enum BagType{
    Canvas,
    Paper
}

and

import {BagType} from "./bagType";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM