How do you implement multiple interfaces in a class?

I want to implement both interfaces in a universal class. How to do it?

interface first {
    name: string,
    age: number
}

interface second {
    product: string,
    available: boolean,
    amount: number
}

class generics <T>{

}
+6
source share
2 answers

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

class generics <T> implements first, second

Here is the complete code:

interface first {
    name: string,
    age: number
}

interface second {
    product: string,
    available: boolean,
    amount: number
}

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

Playground

+8
source

Just separate the interfaces with a comma, for example:

class generics<T> implements first, second { }
+3
source

All Articles