0

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 ?

TSR
  • 17,242
  • 27
  • 93
  • 197
  • This only happens when using the `--declarations` option in the compiler. In general, this methodology isn't recommended for TypeScript because of the way Microsoft maps their types. Instead, you'll need to do something similar to @Talha 's answer. – Swivel Apr 10 '19 at 16:22

1 Answers1

0

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
Talha
  • 807
  • 9
  • 13