簡體   English   中英

TypeError:Modele_1.default不是構造函數

[英]TypeError: Modele_1.default is not a constructor

我是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; } } 

我嘗試在有默認值和沒有默認值的情況下使用導入,但是兩者都不起作用。

以下絕對可以工作:

export default class Inventaire {

並假設路徑./Modele/Modele是正確的,那么以下內容肯定會起作用:

import Inventaire from "./Modele/Modele";

暫無
暫無

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

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