2016-09-20 4 views
0

Ich habe die folgenden zwei Dateien: bag.jsWie Enum importieren in Typoskript

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); 
    } 
} 

und bagType.js

enum BagType { 

    Canvas, 
    Paper 
} 

Meine Frage ist die nächste: Wie kann ich importieren Sie die Enum BagType zur Bag-Klasse?

+0

Mögliche Duplikat von [Wie ein Enum importieren] (https://stackoverflow.com/questions/38553097/how -to-import-an-enum) – EnverOsmanov

Antwort

2

ich es ausprobiert und es funktionierte mit:

export enum BagType{ 
    Canvas, 
    Paper 
} 

und

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

Ich habe das Export-Tag von Anfang an vergessen. Vielen Dank. – GaborH

Verwandte Themen