TS4060: The export function's return type refers to a private name 'class' which is being used

I'm facing an issue here. Typescript keeps throwing this error:

TS4060: Return type of exported function has or is using private name 'class' Student

test.ts

export default function EXPORTMODULE(GreetingText:string) {

    class Student {
        name: string;

        constructor(name: string) {
            this.name = name;
        }

        greet() {
            return `"${GreetingText}, " + this.greeting`;
        }
    }

    class Teacher {
        name: string;

        constructor(name: string) {
            this.name = name;
        }

        greet() {
            return `"${GreetingText}, " + this.greeting`;
        }
    }
    class Professor {
        name: string;

        constructor(name: string) {
            this.name = name;
        }

        greet() {
            return `"${GreetingText}, " + this.greeting`;
        }
    }
    return {Professor, Student, Teacher}
}

Even though I paste the same code on Typescript Playground, it compiles without any errors.

To replicate:

usage.ts

console.log('hello world app')
import module from './test';
const moduleES = module('Holla')
const moduleFR = module('Salut')
const moduleEN = module('Hello')

const greeterESStudent = new moduleES.Student("world");
console.log(greeterESStudent.greet())

const greeterFRStudent = new moduleES.Student("world");
console.log(greeterFRStudent.greet())


const greeterESTeacher= new moduleFR.Teacher("world");
console.log(greeterESTeacher.greet())

const greeterFRTeacher= new moduleFR.Student("world");
console.log(greeterFRTeacher.greet())

Answer №1

The best approach is to change the private member to public. It's necessary for proper functionality.

If you attempt to utilize a non-exported type from a different module, an error will occur.

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

Angular Material Slider is failing to display properly

I am struggling to get the Angular Material Slider to render correctly in my project. Here is the code I have been using: <div class="row formField" ng-cloak> <div class="col-md-2"> <div>送貨日期</div> & ...

Javascript code to verify whether the page is currently positioned at the top

How can I use JavaScript to determine if the page is at scroll(0,0)? I have a full-page slider that needs to pause when the page is no longer at the top. The page may not be scrolled manually, as there are internal HTML # links that could load the page d ...

Arranging JSON elements according to a separate array in Angular 2 or Node.js

Looking for a solution with optimal performance, I am seeking to achieve the rearrangement of a list using either Angular2 or NodeJS. My input consists of user fruit preferences' IDs {15, 43, 55, 67, 98}; In addition, I have a JSON object containin ...

"Utilizing React.js to implement white-space styling on numeric values for

I am a beginner in Reactjs and eager to learn and improve. Here is some code I have been working on: there's an <h1> element with the text "test", and beneath it, I want to display numbers vertically like this: 1:1, 1:2, 1:3. However, the CSS do ...

Error Alert: Attempting to access the 'prototype' property of an undefined value has resulted in a TypeError after switching to react-scripts version 4.0.3

I encountered a problem where I received the following error message: (Uncaught Error: Module build failed (from ./node_modules/source-map-loader/dist/cjs.js)). After attempting to resolve it by using npm install, a new error popped up in the console: path ...

AngularJS is receiving an array of null inputs

I have a form where data from my DB is displayed through WebApi. One of the controls will contain an array of values. There is a scenario where the user can edit and save it using the PUT function. Controller : $scope.Put= function () { $scope.i ...

Obtain access to the child canvas element within the parent component

I'm currently working on an app that allows users to sign with a digital pointer. As part of the project, I have integrated react-canvas-signature. My next task is to capture the signature from the canvas and display it in a popup. According to thei ...

Redis data retrieval is successful on the second attempt

I am utilizing a Redis database along with express routing to create an API. My stack includes node.js and ioredis as well. The process involves connecting to Redis, fetching keys related to a specific date, and then retrieving the data associated with th ...

A guide on attaching files to CouchDB using the Couchdb4j library

I'm facing a challenge with using a Java application to attach system files to a Couchdb database using the Couchdb4J library. Despite trying to modify the code provided, I keep encountering an unresolved error. Can anyone point out where I went wrong ...

Sending Image Data in Base64 Format with Ajax - Dealing with Truncated Data

My current challenge involves sending Base64 image data through ajax to the Server. I've noticed that sometimes all the pictures are successfully sent, but other times only a few make it through. Does anyone have suggestions on how to implement error ...

"Mastering the art of passing variables within the index parameter for JavaScript push method

I need help passing a variable inside index in JavaScript push while working with Angular. Here is my current code: angular.forEach(Val, function (Value,Key) { angular.forEach(Value, function (Value1,Key1) { saveDetailArr.push({ 'option_i ...

showing a single element from an array generated by ng-repeat

I am currently working on handling a large JSON file and displaying it using ng-repeat. However, I encountered a problem where I need to split the 'abilities' item and present it in a table format. I tried using a filter to divide the string into ...

Error: Node Command Line Tool cannot be located using NVM bash

Creating a basic node CLI tool has proven to be challenging when using NVM. Despite installing node locally and attempting to switch to system with nvm use system, the CLI file remains inaccessible. The code snippet includes the following shell designation ...

Tips for gathering an array of checkboxes within a dynamic array of items using Vue.js and Vuetify

I am currently working on a role permission system where I have defined a resource array containing items that users can access, as well as checks representing the permissions for each resource. My goal is to dynamically assign a role with these resources ...

How can I retrieve a password entered in a Material UI Textfield?

My code is functioning properly, but I would like to enhance it by adding an option for users to view the password they are typing. Is there a way to implement this feature? const [email, setEmail] = useState(''); const [password, setPassword] = ...

Is there a way to update a single element within an array without triggering a refresh of the entire array?

Is there a way to prevent the component from rerendering every time new data is input? I attempted to memoize each cell but I am still facing the same issue. Any suggestions on how to accomplish this? import React, { useState, memo } from "react&quo ...

What is the impact of memory on NodeJS performance?

Currently delving into a book on NodeJS, I stumbled upon an intriguing example: const express = require('express') const bodyParser = require('body-parser') const app = express() var tweets = [] app.listen('8000', '172 ...

Keep the music playing by turning the page and using Amplitude.js to continue the song

I have implemented Amplitude.js to play dynamic songs using a server-side php script. My objective is to determine if a song is currently playing, and if so, before navigating away from the page, save the song's index and current position (in percenta ...

Tips for accessing the value of a DOM node during the first render

I am attempting to extract a value from an input textbox during the initial rendering process using useRef, but I am encountering the following error: " ref is not a prop. Trying to access it will result in undefined being returned. If you need to ac ...

Cannot access array method(s) using MyObject.prototype.reduce callback

As I delve into prototyping, I encountered an issue with using forEach and reduce on my ArraySet prototype. The arrow function callback works well with forEach, but I hit a roadblock with reduce. It seems the notation that works for a normal Array doesn&ap ...