2017-08-05 6 views
1

1つの名前空間で複数のファイルにタイプスクリプトコードを書き込もうとしています。しかし、クラスconfigAAAクラスに使用すると、Configは定義されていないため、構文エラーが発生します。どうして?複数ファイルにまたがるTypescriptネームスペース

チェックこの例:

file: services/Config/index.ts

export namespace Services { 
    export class Config { 
     /* class methods */ 
    } 
} 

file: services/AAA/index.ts

/// <reference path = "./../Config/index.ts" /> 
export namespace Service { 
    export class AAAA { 
     private config = new Config(); <-- Error is here 
     /* class methods */ 
    } 
} 
+0

名前空間を使用しないでください。 – unional

答えて

0

あなたが名前空間をエクスポートいけない:

namespace Services { 
export class Config { 
    /* class methods */ 
} 
} 

/// <reference path = "../Config/index.ts"/> 
namespace Service { 
export class AAAA { 
    private config = new Config(); <-- Error is here 
    /* class methods */ 
} 
} 

https://www.typescriptlang.org/docs/handbook/namespaces.html

+0

私はこの問題は輸出用語ではないと思います。エクスポートせずに、私はそのエラーが表示されます: '名前 'Config'を見つけることができません。 – zerob4wl

+0

参照構文を見てください。あなたは試してみましたか: '/// ' 私はあなたが同じフォルダに両方のファイルを置くことを提案し、あなたの問題です。 – Cleriston

+0

両方のファイルを同じディレクトリに置くことは重要ですか? – zerob4wl