How do I implement multiple interfaces in a class?

后端 未结 2 1129
醉梦人生
醉梦人生 2020-12-25 10:39

I want to implement both the interfaces in the generic class. How do I do that?

interface first {
    name: string,
    age: number
}

interface second {
            


        
2条回答
  •  既然无缘
    2020-12-25 11:41

    Use a , to separate the interfaces you want to implement. That gives the following class declaration :

    class generics  implements first, second
    

    Here is the complete code :

    interface first {
        name: string,
        age: number
    }
    
    interface second {
        product: string,
        available: boolean,
        amount: number
    }
    
    class generics  implements first, second {
        name: string;
        age: number;
        product: string;
        available: boolean;
        amount: number;
    }
    

    Playground link

提交回复
热议问题