TypeError:Modele_1.default不是构造函数

时间:2018-02-07 21:40:53

标签: javascript typescript importerror

我是Webpack和typescrypt的新手,所以这可能是一个简单的错误,但我无法找到它。

我从main.ts文件导入我的模型:



import View from "./View/View";
import Controller from "./Controller/Controller";
import Inventaire from "./Modele/Modele";

require("tether");
require("bootstrap");

function main(): void {
    let model = new Inventaire();
    let controller = new Controller(model);
    let view = new View(controller);
}

main();




但是当我运行它时,我在控制台中出错:

TypeError: Modele_1.default is not a constructor

model.ts:



export default class Inventaire {

    private _achats: Achat[];

    constructor(achats: Achat[] = [/*default values*/]) {
        this._achats = achats;
    };
    /*...*/

}

class Achat {
    Nom: string;
    private _Quantite: number;
    Prix: number;
    Description: string;
    Poids: number;
    Photo?: string[]; //path of the image

    constructor(nom: string, prix: number, description: string, poids: number = 0, photo?: string[]) {
        this.Nom = nom;
        this.Prix = prix;
        this.Description = description;
        this.Poids = poids;
        if (photo) this.Photo = photo;
    }

}

class ModelePanier {
    Contenu: Achat[];
    Quantite: number = this.Contenu.length;

    PrixTotal(): number {
        let prix: number = 0;
        for (let achat of  this.Contenu) {
            prix += achat.Prix;
        }
        return prix;
    }
}




我尝试使用带有和不带默认值的导入,但两者都不起作用。

1 个答案:

答案 0 :(得分:0)

以下一定会奏效:

export default class Inventaire {

假设路径./Modele/Modele正确,以下内容肯定会有效:

import Inventaire from "./Modele/Modele";