default interface typescript in javascript

To define an interface in TypeScript, you can simply use the "interface" keyword followed by the name of the interface and the list of properties and their types. Here's an example of a simple interface for a person:

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

To make this interface the default export in the module, you can use the "export default" statement before the interface definition, like this:

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

In the above code, we have defined an interface named "Person" and exported it as the default export in the module, which means that when we import this module in another file, this interface will be the default export.

To use the exported default interface in another file, you can import the module and use it like this:

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

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

In the above code, we have imported the default export of the "person" module and used it to define a new object of type "Person".

gistlibby LogSnag