0
votes

I am having a problem re-exporting in my typescript project

I have class Layer and I declare it like so:

// Layer.ts  
export default class Layer{//code}

And I have another file to re-export all related files

// layers.ts
export Layer from "./Layer";

On compilation I get the following errors:

src/layer/layers.ts(1,14): error TS1005: ';' expected.
src/layer/layers.ts(1,19): error TS1005: ';' expected.
src/layer/layers.ts(2,1): error TS1128: Declaration or statement expected.
src/layer/layers.ts(2,24): error TS1005: ';' expected.
src/layer/layers.ts(2,29): error TS1005: ';' expected.

Also another related error: When declaring an interface with the export keyword like so:

export default interface MyInterface<V>{
    method():V;
}

I get this error again:

MyInterface.ts(1,26): error TS1005: ';' expected.
1

1 Answers

1
votes

For the first part: export { default as Layer} from './Layer';

For the second part, an interface cannot be exported as default since interfaces are not represented by anything in the generated javascript code.

So get rid of the default keyword:

export interface MyInterface<V>{
    method():V;
}

importing using the ES6 module syntax could look like:

import { MyInterface } from './MyInterface';

class A implements MyInterface<string> {}