GaborH
GaborH

Reputation: 719

How to import enum in Typescript

I have the following two files: 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

enum BagType {

    Canvas,
    Paper
}

My question is the next: How can I import the enum BagType to the Bag class?

Upvotes: 0

Views: 2470

Answers (1)

SilentLupin
SilentLupin

Reputation: 658

I tried it and it worked with:

export enum BagType{
    Canvas,
    Paper
}

and

import {BagType} from "./bagType";

Upvotes: 3

Related Questions