The exported class's public property references a private name

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.

Answer №1

My solution was to resolve the issue by exporting and importing the necessary library:

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

Additionally, I made sure to import the library whenever it was utilized in the codebase.

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Typescript error: RequestInit not properly initialized

I'm encountering an issue while using fetch to call an API in a typescript file. The browser is throwing an error stating that const configInit must be initialized, even though I believe it is already. Any suggestions on how to resolve this? Thank you ...

Encountering an error in TypeScript and ng2 rc.1: Error message (20, 15) TS2304 indicates that the name 'module' cannot be found

Having trouble with TypeScript and ng2 rc.1 - getting Error:(20, 15) TS2304: Cannot find name 'module'. I encountered this issue when trying to use a directive of the module in my code: @Component({ selector: 'Notes1', moduleI ...

Adjust the background color of the header as you scroll

Seeking assistance in adjusting the background color of my header upon scrolling. This is my current implementation: header.component.ts export class HeaderComponent { ngOnInit(): void { const header = document.querySelector('.header'); ...

Optimal method for retrieving data from a JSON object using the object's ID with a map

Can you teach me how to locate a json object in JavaScript? Here is a sample Json: { "Employees" : [ { "userId":"rirani", "jobTitleName":"Developer", "preferredFullName":"Romin Irani", "employeeCode":"E1", "region":"CA", "phoneNumber":"408-1234567", " ...

Creating an array of input data for component, implementing data formatting in TypeScript for Angular or React applications

Here is an example of the input for the component. When this input is passed to the component, the output displays correctly. const data = [ ['Rank', 'Player', 'Player', 'Player'], ['1& ...

Tips for sending a value to a container component

Within my task management application, I have implemented two selectors: export const selectFilter = (state: RootState) => state.visibilityFilter export const selectVisibleTodos = createSelector( [selectTodos, selectFilter], (todos: Todo[], filter : ...

The deployment of the Next.js project encountered issues due to TypeScript types

Currently, I am in the process of deploying my project using Vercel. The project was built using Next.js and TypeScript. I have integrated Next-auth with the credentials provider for authentication. By default, this authentication package includes an obje ...

How can one specify a type in Typescript with a precise number of properties with unspecified names?

Imagine I have a variable with a name and a value, both of which I need for a specific task such as logging. This can be achieved in the following way: const some_variable = "abcdef" const another_variable = 12345 const log1 = (name: string, value: any) ...

Can wildcard paths be imported in React using Typescript?

Is there a way to dynamically import a React Typescript Component from a wildcard path, similar to the following code snippet? const Component = loadable( () => import(`../../../src/**/*/${component_name}`), ); I have searched numerous solutions on ...

Which RxJS operators necessitate unsubscription?

It can be confusing to know which operators in RxJS must be unsubscribed from to prevent subscription leaks. Some, like forkJoin, complete automatically, while others, such as combineLatest, never complete. Is there a comprehensive list or guideline availa ...

Debug a Typescript-enabled Koa application remotely from a Docker container using Webstorm

Issue: Currently facing challenges while setting up a new NodeJS Project using KoaJS, Typescript, and Docker. The initial setup went as planned, but encountering some difficulties with remote debugging - or at least it seems so from my perspective. When s ...

Can you explain how to compare a value with a set of enum values?

How can you compare a value to a list of enum values, using TypeScript? For example, in Java: public enum Animal { CAT, DOG, BIRD, SNAKE public static EnumSet<Animal> Mammals = EnumSet.of(CAT, DOG); } Usage: Animal.Mammals.contains(myPet) ...

Tips for extracting value from a dynamic element in Angular 2

Here is the HTML code: <tr *ngFor="let item of items"> <td #id>{{item.id}}</td> <td>{{item.comment}}</td> <td> <i class="fa fa-trash-o" aria-hidden="true" (click)="deleteTime(id.value)"> ...

Mongoose: An unexpected error has occurred

Recently, I developed an express app with a nested app called users using Typescript. The structure of my app.js file is as follows: ///<reference path='d.ts/DefinitelyTyped/node/node.d.ts' /> ///<reference path='d.ts/DefinitelyTyp ...

What are the benefits and drawbacks of utilizing two distinct methods to regulate a component in Vue?

I've developed two components that display "on" or "off" text, along with a button that toggles the state of both components. Here is the link to the codesandbox for reference: https://codesandbox.io/s/serene-mclean-1hychc?file=/src/views/Home.vue A ...

Creating a unique user interface for VSCode extension

Recently, I've delved into the world of developing extensions for Visual Studio. Unfortunately, my expertise in TypeScript and Visual Studio Code is quite limited. My goal is to create an extension that mirrors the functionality of activate-power-mod ...

Sidenav Angular Material cdkScrollable is an effective tool for creating scrollable

In Angular Material CDK, there is a special Directive called CdkScrollable that allows you to monitor ScrollEvents within a specific container. I am currently attempting to retrieve the CdkScrollable associated with the default MatSidenavContent. Unfor ...

Fill up the table using JSON information and dynamic columns

Below is a snippet of JSON data: { "languageKeys": [{ "id": 1, "project": null, "key": "GENERIC.WELCOME", "languageStrings": [{ "id": 1, "content": "Welcome", "language": { ...

Typescript's approach to function decorators in their original form

I have a basic decorator function in Python that I am using to decorate another function. def decorator(fn): def wrapper(args): print("calling function") fn(args) return wrapper @decorator def printMyName(name): prin ...

Issue encountered with Typescript and Mongoose while operating within a Kubernetes cluster environment with Skaffold configuration

Here is the code snippet, const userSchema = new mongoose.Schema({ email: { type: String, required: true, }, password: { type: String, required: true, }, }); console.log(userSchema); userSchema.statics.build = (user: UserAttrs) =& ...