TS4060:导出函数的返回类型具有或正在使用私有名称“类”

TSR*_*TSR 6 javascript module typescript

我被困在这里。打字稿一直抱怨:

TS4060:导出函数的返回类型具有或正在使用私有名称“类”学生

测试文件

export default  function MODULETOEXPORT(GreetingIntroTxt:string) {

    class Student {
        name: string;

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

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

    class Teacher {
        name: string;

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

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

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

        greet() {
            return `"${GreetingIntroTxt}, " + this.greeting`;
        }
    }
    return {Professor, Student, Teacher}
}
Run Code Online (Sandbox Code Playgroud)

尽管我在Typescript Playground上复制粘贴了完全相同的代码,但我没有收到任何错误并且编译完美。

重现:

用法.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())
Run Code Online (Sandbox Code Playgroud)

Ami*_*adi -1

您应该将私有成员设为公开。这是没有办法解决的。

如果您使用另一个模块中的非导出类型,则会抛出类似的错误。