iPhoneJavaDev
iPhoneJavaDev

Reputation: 825

Export multiple variables from typescript class

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

Answers (1)

Daniel Rothig
Daniel Rothig

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

Related Questions