簡體   English   中英

如何在Typescript中導入枚舉

[英]How to import enum in Typescript

我有以下兩個文件: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);
    }
}

和bagType.js

enum BagType {

    Canvas,
    Paper
}

我的問題是下一個:如何將枚舉BagType導入Bag類?

我嘗試了它,它與:

export enum BagType{
    Canvas,
    Paper
}

import {BagType} from "./bagType";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM