After browsing through this specific question, I realized that the exporting method mentioned didn't quite help me with my problem.
Here is a snippet of the code from cloudFoundry.ts
:
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;
});
}
}
Now, moving on to another file called viewlet.ts
...
import {
CloudFoundry,
OauthToken
} from './cloudFoundry';
...
Despite this setup, TypeScript seems to be flagging an error:
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'.
I did attempt to follow a solution provided here by exporting the import, which resolved the error message.
export var cf = require.__$__nodeRequire<any>('cf-client');
However, I encountered a runtime issue after implementing this change...
cf is not defined: ReferenceError: cf is not defined
at eval (eval at <anonymous> (cloudFoundry.js:41:108)
This error was linked to the following line of code.
eval("this." + _class + " = new(cf)." + (_class.charAt(0).toUpperCase() + _class.slice(1)) + "(this._endpoint)");
If anyone can provide assistance on resolving this matter, it would be highly appreciated.