0
export interface example {
  book:{
    first:number;
    second:string;
  }
}

interface table extends example{
  book:{
    third:null
  }
}

Is it possible to extend same object in typescript ? in some case I only want to use example case without book third

1
  • Example without book third is example right. I did not understand what you want? Commented Aug 2, 2021 at 5:19

1 Answer 1

2

Why not just make third an optional property in the example interface?

export interface example {
  book:{
    first:number;
    second:string;
    third?: null;
  }
}

If you really need to extend example interface, you have to make the types compatible, ie the extended book needs at least all the properties, the base interface has ...

export interface example {
  book:{
    first:number;
    second:string;
  }
}

interface table extends example{
  book:{
    first: number;
    second: string;
    third:null
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.