export default interface in typescript

To export a default interface in TypeScript, you can define the interface as usual and then use the export default keywords before the interface definition. Here's an example:

index.ts
export default interface Person {
  name: string;
  age: number;
  address: string;
}
86 chars
6 lines

In this example, we define an interface Person with three properties. The interface is marked as the default export for this module by using the export default keywords before the interface keyword.

To import this default interface in another module, we can use import Person from './person'. Note that we don't need to specify the name of the exported interface because it's the default export.

index.ts
import Person from './person';

const john: Person = {
  name: 'John',
  age: 30,
  address: '123 Main St',
};
111 chars
8 lines

In this example, we import the Person interface from the person module using import Person from './person'. We can then use the Person interface like any other interface in TypeScript.

gistlibby LogSnag