传递ES6模块导入选项不起作用 [英] Pass options to ES6 module imports not working

查看:162
本文介绍了传递ES6模块导入选项不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Stackoverflow 问题之后,我正在尝试将选项传递给ES6进口?

Following this Stackoverflow question, I am trying to pass options to ES6 imports?

此工作正常:

export default (Param1:any, Param2:any) => {
    return class Foo {
        constructor() {
            console.log(Param1);
        }
    }
}

但现在我需要返回不止一个班,所以我尝试了这个:

But now I need to return more than one class so I tried this:

export default (Param1: any, Param2: any)=>{

       class Foo {
            constructor() {
                console.log(Param1);
            }
        }
       class Bar {
            constructor() {
                console.log(Param1);
            }
        }
        return {Foo, Bar}
}

但是我在编译时遇到以下错误:

But I got the following error on compilation:


TS4060:导出函数的返回类型具有或正在使用私有名称
Foo TS4060:返回类型的导出函数已经或正在使用私有
名称栏

TS4060: Return type of exported function has or is using private name Foo TS4060: Return type of exported function has or is using private name Bar

如何将选项传递给ES6导入多个类的导入?

How to pass options to ES6 imports that imports multiple class ?

推荐答案

我认为您应该单独导出类:

I think you should just export the classes separately:

export class Foo {
    constructor(Param1) {
        console.log(Param1);
    }
}

export class Bar {
    constructor(Param1) {
        console.log(Param1);
    }
}

然后你可以这样导入:

import {Foo, Bar} from './your/path/to/module.js

这篇关于传递ES6模块导入选项不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆