0
0
Typescriptprogramming~10 mins

Multiple interface extension in Typescript - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Multiple interface extension
Define Interface A
Define Interface B
Define Interface C extends A, B
Create Object of Interface C
Access properties from A and B via C
This flow shows how one interface can extend multiple interfaces, combining their properties into one.
Execution Sample
Typescript
interface A {
  name: string;
}
interface B {
  age: number;
}
interface C extends A, B {}
const person: C = { name: "Alice", age: 30 };
Defines interfaces A and B, then interface C extends both. Creates an object person of type C with properties from A and B.
Execution Table
StepActionEvaluationResult
1Define interface A with property name:stringNo runtime effectInterface A ready
2Define interface B with property age:numberNo runtime effectInterface B ready
3Define interface C extends A, BNo runtime effectInterface C combines A and B
4Create object person of type C with name and ageCheck properties match A and Bperson = {name: "Alice", age: 30}
5Access person.nameRetrieve string"Alice"
6Access person.ageRetrieve number30
💡 All properties from A and B are present in C, so object creation succeeds.
Variable Tracker
VariableStartAfter Step 4After Step 5After Step 6
personundefined{name: "Alice", age: 30}{name: "Alice", age: 30}{name: "Alice", age: 30}
person.nameundefined"Alice""Alice""Alice"
person.ageundefined303030
Key Moments - 3 Insights
Why can interface C have properties from both A and B?
Because interface C extends both A and B, it inherits all their properties combined, as shown in execution_table step 3.
Does defining interfaces affect runtime code?
No, interfaces are only for type checking and do not produce JavaScript code, as seen in steps 1-3 where evaluation is 'No runtime effect'.
What happens if person misses a property from A or B?
TypeScript will give a type error because person must have all properties from both interfaces, as checked in step 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what properties does interface C have at step 3?
AOnly properties from interface A
BOnly properties from interface B
CProperties from both A and B combined
DNo properties
💡 Hint
Check execution_table row 3 where interface C extends A and B.
At which step is the object 'person' created with properties from both interfaces?
AStep 4
BStep 2
CStep 5
DStep 6
💡 Hint
Look at execution_table row 4 where person is assigned.
If interface C did not extend B, what would happen when creating 'person' with age property?
ANo error, age is optional
BType error because age is not defined in C
Cperson would have age but not name
Dperson would have both properties anyway
💡 Hint
Refer to key_moments about missing properties causing errors.
Concept Snapshot
interface C extends A, B {
  // C has all properties from A and B combined
}

const obj: C = { ... } // must have all properties

Interfaces only check types, no runtime code

Multiple interface extension merges properties
Full Transcript
This example shows how in TypeScript, one interface can extend multiple interfaces to combine their properties. Interfaces A and B define separate properties. Interface C extends both, so it includes all properties from A and B. When creating an object of type C, it must have all these properties. Interfaces do not produce runtime code; they only help TypeScript check types. If a property is missing, TypeScript will give an error. This helps keep code safe and clear.