简体   繁体   中英

Pass options to ES6 module imports not working

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

This worked fine:

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: 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

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);
    }
}

Then you can import like so:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM