2017-10-15 55 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

你是完全正确的! 我认为编译器是两次通过的,而且这些语句的顺序没有强加。 因为我认为这种导入/导出机制应该是自动的,所以我宁愿隐藏它在代码的末尾!太糟糕了 !

谢谢

相关问题