Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript. How to export two classes (in separate files) in one module?

Tags:

typescript

I have two classes declared in two separate files.

a.ts

export class AClass {

  public constructor () {
    console.log('AClass');
  }

}

b.ts

export class BClass {

  public constructor () {
    console.log('BClass');
  }

}

I want to merge them in one module. How I can realise it?

///<reference path='a.ts' />
///<reference path='b.ts' />

module Common {

  export class A extends AClass {}
  export class B extends BClass {}

}

says:

Cannot find name 'AClass'.

and

Cannot find name 'BClass'.

I can import classes

import AClass = require('a');
import BClass = require('b');

module Common {

}

But how I can correctly export them?

Cannot find any information in documentation. Please, tell me the best way to realise declarations in one module? Thank you in advance

like image 719
indapublic Avatar asked Mar 20 '15 14:03

indapublic


1 Answers

I do it like this:

m/a.ts

export class A {
}

m/b.ts

export class B {
}

m/index.ts

export { A } from './a.ts';
export { B } from './b.ts';

And then I do: consumer.ts

import { A, B } from './m';
like image 128
Josh Wulf Avatar answered Nov 02 '22 03:11

Josh Wulf