2016-09-20 173 views
0
導入枚舉

我有以下兩個文件: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類?

+0

[如何導入枚舉(可能的重複https://stackoverflow.com/questions/38553097/how -en-import-an-enum) – EnverOsmanov

回答

2

我嘗試過了,它的工作:

export enum BagType{ 
    Canvas, 
    Paper 
} 

import {BagType} from "./bagType"; 
+1

我從一開始就忘記了導出標籤。謝謝。 – GaborH