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

标签 javascript typescript module

我被困在这里。 Typescript 一直在提示:

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



测试.ts
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}
}

虽然我在 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())

最佳答案

您应该将私有(private)成员设为公开。没有办法解决这个问题。
如果您使用来自另一个模块的非导出类型,则会引发类似情况。

关于javascript - TS4060 : Return type of exported function has or is using private name 'class' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55214523/

相关文章:

perl - Module::Starter 的 manifest.t 中预期的开发过程是什么?

javascript - Nodejs 引用 module.exports

javascript - 为什么 jQuery.sortable 的 ajax 会多次执行更新?

javascript - 在 JavaScript 或 jQuery 中从 URI 获取附加到 URN 的数字

javascript - 使用 Vanilla JS 在下拉列表中将所选选项设为大写

具有可变数量参数的 console.log 的 Typescript 包装器

类型的 TypeScript 联合被解析为类型的交集

android - 未安装 Ionic firebase 手机身份验证插件

.net - orchard如何处理模块

javascript - Rails 应用程序 : require bootstrap vs require bootstrap-sprockets