Hy is default export of interfaces restricted in TypeScript?

Why is there a limitation on exporting an interface by default in TypeScript?

I’m using TypeScript 1.5 beta, and when attempting to export an interface as the default export, the following code causes an error in both Visual Studio and WebStorm:

export default interface Foo {...}

However, the following code works correctly:

interface Foo {...}
export default Foo;

Is this behavior by design, a bug, or am I doing something wrong?

EDIT: Thank you for your answer. This raises another question: what is the recommended way to import an interface using the ES6 module syntax?

This works:

// Foo.ts
export interface Foo {}

// Bar.ts
import { Foo } from 'Foo'; // Notice the curly braces

class Bar {
    constructor(foo: Foo) {}
}

But, since this works, why not allow default exports for interfaces and avoid using curly braces?

// Foo.ts
export default interface Foo {}

// Bar.ts
import Foo from 'Foo'; // Notice, no curly braces!

class Bar {
    constructor(foo: Foo) {}
}

typescript export interface: Why is the default export of interfaces restricted, and what is the recommended approach for using them with import/export syntax?

Hello,

When working with TypeScript, it’s essential to avoid default exports for interfaces since TypeScript does not directly support them. Instead, using named exports for interfaces ensures proper compatibility and avoids potential issues.

Here’s a simple example:

// Foo.ts
export interface Foo {
  // properties
}

// Bar.ts
import { Foo } from './Foo'; // Using named imports

class Bar {
  constructor(foo: Foo) {}
}

This approach is aligned with the ES6 module system and is the recommended method for exporting interfaces in TypeScript.

Best regards