2016-03-30 6 views
1

私はこのquestionを見ていましたが、エクスポートは私の問題を解決しません。エクスポートされたクラスのパブリックプロパティは、プライベートネームを持っていますか、または使用しています

export var cf = require.__$__nodeRequire<any>('cf-client'); 

export class CloudFoundry { 

    apps: typeof cf.Apps; 
    cloudController: typeof cf.CloudController; 
    domains: typeof cf.Domains; 
    logs: typeof cf.Logs; 
    usersUAA: typeof cf.UsersUAA; 
    routes: typeof cf.Routes; 
    organizations: typeof cf.Organizations; 
    spaces: typeof cf.Spaces; 
    services: typeof cf.Services; 

constructor() { 
     // load services with proper token + config 
     this.initializeServices(); 
     return; 
    } 

    .... 

    private initializeServices() { 
     ['cloudController', 'apps', 'domains', 'organizations', 'routes', 'spaces', 'services', 'logs','usersUAA'].map(function(_class){ 
      eval(`this.${_class} = new(cf).${_class.charAt(0).toUpperCase() + _class.slice(1)}(this._endpoint)`); 
      eval(`this.${_class}.setToken(this.token)`); 
     }, this); 
     this.cloudController.getInfo().then((result) => { 
      this.usersUAA.setEndPoint(result.authorization_endpoint); 
      this.logs.setEndPoint(result.logging_endpoint); 
     }).catch((e) => { 
      console.log('ERROR ' + e); 
      return; 
     }); 
    } 
} 

その後、別のファイルviewlet.ts

... 
import { 
    CloudFoundry, 
    OauthToken 
} from './cloudFoundry'; 
... 

しかしtypescriptですが、次のエラーを投げている:

は、私は、次のコードスニペット、cloudFoundry.tsを持っています。

cloudFoundry.ts(24,15): Public property 'apps' of exported class has or is using private name 'cf'. 
cloudFoundry.ts(25,26): Public property 'cloudController' of exported class has or is using private name 'cf'. 
cloudFoundry.ts(26,18): Public property 'domains' of exported class has or is using private name 'cf'. 
cloudFoundry.ts(27,15): Public property 'logs' of exported class has or is using private name 'cf'. 
cloudFoundry.ts(28,19): Public property 'usersUAA' of exported class has or is using private name 'cf'. 
cloudFoundry.ts(29,17): Public property 'routes' of exported class has or is using private name 'cf'. 
cloudFoundry.ts(30,24): Public property 'organizations' of exported class has or is using private name 'cf'. 
cloudFoundry.ts(31,17): Public property 'spaces' of exported class has or is using private name 'cf'. 
cloudFoundry.ts(32,19): Public property 'services' of exported class has or is using private name 'cf'. 

私はインポートをエクスポートすることによってhereを言及し、少なくともエラーを処分したということでしたトリックを試してみました。

export var cf = require.__$__nodeRequire<any>('cf-client'); 

しかし、その後、私は、実行時に次の問題を得た...

cf is not defined: ReferenceError: cf is not defined 
    at eval (eval at <anonymous> (cloudFoundry.js:41:108) 

は行を次のように言及しています。

eval("this." + _class + " = new(cf)." + (_class.charAt(0).toUpperCase() + _class.slice(1)) + "(this._endpoint)"); 

これを修正しようとすると何か助けていただければ幸いです。それは同様に使用されたときに

export var cf = require.__$__nodeRequire<any>('cf-client'); 
export class CloudFoundry { 
    apps: typeof cf.Apps; 
    ... 

ライブラリをインポートする:

+0

これを読んだ後に動作しませんでした@AngelAngelのうーん... –

+0

(私はtypescriptですに新たなんだ) - > https://github.com/Microsoft/TypeScript/issues/6307、あなたがする必要がありますそれを使用するにはcf.xxxをエクスポートしますか?私の英語のために申し訳ありませんが、私は理解して欲しい、タイプを輸出 –

答えて

0

私はインポートをエクスポートすることによって、これを固定してしまいました。

private initializeServices() { 
    var cf = require.__$__nodeRequire<any>('cf-client'); 
    .... 
関連する問題