Boogie
Boogie

Reputation: 818

typescript 0.9 interface export. is it possible?

As I read from typescript now you can export classes like this:

// client.ts 
    class Client { 
        constructor(public name: string, public description: string) { } 
    } 
    export = Client; 

// app.ts 
import MyClient = require('./client'); 
var myClient = new MyClient("Joe Smith", "My #1 client");

But, is there any way to export interfaces?.

Right now I'm getting an error saying:

error TS1003: Identifier expected.

when I try to do something like this:

// INotifier.ts
    interface INotifier {
        // code
    }
    export = INotifier;

Upvotes: 2

Views: 1228

Answers (1)

Fenton
Fenton

Reputation: 251292

I have tried this in Visual Studio and this works for me, using the import syntax (answer updated to reflect changes in the TypeScript language):

file1.ts

interface IPoint {
    getDist(): number;
}

export = IPoint;

app.ts

// Obsolete syntax
//import example = module('file1');

// Newer syntax
import example = require('file1');

class Point implements example {
    getDist() {
        return 1;
    }
}

Additional note: you won't be able to use ECMAScript 6 style imports in this situation - as they only work with classes and modules.

//Won't work because it resolves to a "non-module entity"
import * as example from 'file1';

Upvotes: 3

Related Questions