0
votes

I have imported many class files and many interface files into a WebStorm Typescript project.

How can I handle references for the case where one class (single file) references multiple interfaces (multiple files)?

Do I need to have many references to each of the interface files at the top of each class (file)?

Note that I am using Webstorm. I am not sure if this is different but previously I was working on a Typescript application in Visual Studio and I don't recall any reference links being needed at the top of each of the files that contained my classes.

3

3 Answers

1
votes

am not sure if this is different but previously I was working on a Typescript application in Visual Studio and I don't recall any reference links being needed at the top of each of the files that contained my classes.

You can use the good old reference file trick : https://github.com/TypeStrong/grunt-ts#reference

0
votes

I have been doing it like:

import IInterface1 = require('./IInterface1');
import IInterface2 = require('../IInterface2');

class Class1 implements IInterface1, IInterface2 {

}
0
votes

You can create master-reference file in a next manner (mymodule.ts):

export import IInterface1 = require('./IInterface1');
export import IInterface2 = require('../IInterface2');

and use it:

import mod = require('./mymodule');

export function foo(v: mod.IInterface1) {
}

This trick - 'export import' does not described in official TS docs, but works fine