zl程序教程

您现在的位置是:首页 >  前端

当前栏目

[TypeScript ] What Happens to Compiled Interfaces

typescript to What
2023-09-14 09:00:53 时间

This lesson covers using your first TypeScript Interface and what happens to the Interface when it is compiled down to JavaScript.

 

Define the interfaces:

// interfaces.ts

export interface Person {
    name: String
}

export interface SocialNetwork{
    title: String;
    getPeople(): Person[];
}

 

Use interface:

import {SocialNetwork} from './interfaces';

class SocialNetworks implements SocialNetwork{
    title = "Facebook";

    getPeople(){
        return [{name: 'John'}]
    }
}

new SocialNetworks();

 

To notice that, interfaces won't output to the js file, it is just used when compile time.