2017-10-15 54 views
0

新建打字稿(而不是面向對象的設計)的財產「倉庫」我不明白髮生了什麼打字稿錯誤無法讀取未定義

文件application.ts

class 
    APPLICATION{ 

     constructor(){ 
      console.log("constructor APPLICATION") 
      this.database = new REPOSITORY 
     } 

     database: REPOSITORY 
} 

new APPLICATION 

import { REPOSITORY } from "./repository" 

文件repository.ts

export 

class 
    REPOSITORY { 

     constructor() { 
      console.log("constructor de REPOSITORY") 
     } 

} 

和我得到的錯誤

this.database = new repository_1.REPOSITORY; 
            ^

類型錯誤:無法讀取性能在新的應用的不確定 '倉庫'(Z:\文檔\披\Développement公司\打字稿\測試\ application.js中:6:41)

任何想法?

回答

0

我不相信進口是懸掛的。嘗試在代碼中移動import { REPOSITORY } from "./repository"

0

REPOSITORY是在構造函數用於APPLICATION後,會出現你的import語句REPOSITORY,這意味着它不會在構造函數尚未定義(從import語句產生的變量賦值不懸掛)。您需要在使用之前導入:

import { REPOSITORY } from "./repository" 

class APPLICATION { 
    constructor(){ 
     console.log("constructor APPLICATION") 
     this.database = new REPOSITORY(); 
    } 
    database: REPOSITORY 
} 
0

你是完全正確的! 我認爲編譯器是兩次通過的,而且這些語句的順序沒有強加。 因爲我認爲這種導入/導出機制應該是自動的,所以我寧願隱藏它在代碼的末尾!太糟糕了 !

謝謝

相關問題