Reputation: 825
I have a the following sample.ts:
class Sample {
var1;
var2;
...
}
export default new Sample();
In another class, i imported it using:
import sample from './sample';
And use it as:
sample.var1;
But I would like to access var2 without using sample.var2
. I thought of exporting var2
as well, but I'm not sure if that is possible. I want something like below, so I can use var2
directly when i import the file.
class Sample {...}
export default new Sample(), var2;
Upvotes: 1
Views: 6992
Reputation: 706
Replace your export statement with
const sampleToExport = new Sample();
export sample = sampleToExport;
export var2 = sampleToExport.var2;
You can then import it like this:
import { sample, var2 } from './sample'
Upvotes: 2