Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to inherit an interface from multiple other interfaces in TypeScript

Hi angular community,

Is it possible to include three interfaces nested inside another, think my code will explain it more than my sentence: I am trying to implement the interface IProject1 & IProject2 & IProject3 to be part of the IAdmin2 interface:

Thanks in advance

 import {IBusiness} from "./business";
 import {ITechnology} from "./technology";
 export interface IAdmin2 {
     id: number;
     business_id: number;
     technology_ids: number[];
     trigram: string;
     position: string;
     years_experience: number;
     notification: boolean;
     availability: any;
     form_admin2_file: File;
     business: IBusiness;
     technologies: ITechnology[];
     admin2Translations: any;
     translations: any;
    delete: any;
    data: any;
  ** Include interface Iproject1**
  ** Include interface Iproject2**
  ** Include interface Iproject3**
 }


 import {ITechnology} from "./technology";
 import {IProjectFile} from "./project-file";
 export interface IProject1 {
     id: number;
    name: string;
    start_date: any;
    technologies: ITechnology[];
    description: string;
    sector_id: number;
    end_date: any;
    team_size: number;
}

 import {ITechnology} from "./technology";
 import {IProjectFile} from "./project-file";
 export interface IProject2 {
     id: number;
    name: string;
    start_date: any;
    technologies: ITechnology[];
    description: string;
    sector_id: number;
    end_date: any;
    team_size: number;
}

 import {ITechnology} from "./technology";
 import {IProjectFile} from "./project-file";
 export interface IProject3 {
     id: number;
    name: string;
    start_date: any;
    technologies: ITechnology[];
    description: string;
    sector_id: number;
    end_date: any;
    team_size: number;
}
like image 767
Emile Cantero Avatar asked Oct 18 '25 02:10

Emile Cantero


1 Answers

In TypeScript you can inherit an interface from one or more base interfaces:

interface IProject1 {
}

interface IProject2 {
}

interface IProject3 {
}

interface IAdmin2 extends IProject1, IProject2, IProject3 {
}

As a result, implementations of IAdmin2 will also have to implement IProject1, IProject2 and IProject3. You can also check the official documentation of interfaces.

like image 193
Sefe Avatar answered Oct 19 '25 18:10

Sefe