Challenge - 5 Problems
Multiple Interface Extension Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of multiple interface extension with overlapping properties
What is the output of the following TypeScript code when compiled and run with Node.js (ignoring type errors)?
Typescript
interface A {
x: number;
}
interface B {
y: string;
}
interface C extends A, B {
z: boolean;
}
const obj: C = { x: 10, y: "hello", z: true };
console.log(obj.x, obj.y, obj.z);Attempts:
2 left
💡 Hint
Interfaces can extend multiple interfaces and combine their properties.
✗ Incorrect
Interface C extends both A and B, so it has all properties x, y, and z. The object obj correctly implements all properties, so logging them prints their values.
❓ Predict Output
intermediate2:00remaining
Property type conflict in multiple interface extension
What error or output occurs when the following TypeScript code is compiled?
Typescript
interface A {
prop: number;
}
interface B {
prop: string;
}
interface C extends A, B {}
const obj: C = { prop: 42 };Attempts:
2 left
💡 Hint
Check if properties with the same name but different types cause conflicts.
✗ Incorrect
TypeScript does not allow interfaces to extend multiple interfaces that declare the same property with incompatible types. This causes a compilation error.
🔧 Debug
advanced2:00remaining
Why does this multiple interface extension cause a type error?
Given the code below, why does TypeScript report an error on the assignment to obj?
Typescript
interface X {
a: number;
}
interface Y {
b: string;
}
interface Z extends X, Y {
a: string;
}
const obj: Z = { a: "test", b: "hello" };Attempts:
2 left
💡 Hint
Look at property 'a' in interfaces X and Z.
✗ Incorrect
Interface Z extends X which has 'a' as number, but Z redeclares 'a' as string, causing a type conflict that TypeScript flags as an error.
🚀 Application
advanced2:00remaining
Designing an interface that extends multiple interfaces with optional properties
You want to create an interface 'Person' that extends interfaces 'Name' and 'Contact'. 'Name' has required properties 'first' and 'last'. 'Contact' has optional properties 'email' and 'phone'. Which interface definition correctly models this?
Attempts:
2 left
💡 Hint
Interfaces can extend multiple interfaces to combine their properties.
✗ Incorrect
Extending both Name and Contact combines required and optional properties correctly. Option C does this directly.
🧠 Conceptual
expert2:00remaining
Understanding property merging in multiple interface extension
Consider these interfaces:
interface A { x: number; }
interface B { x?: number; }
interface C extends A, B {}
What is the type of property 'x' in interface C?
Attempts:
2 left
💡 Hint
Required properties take precedence over optional ones when merging.
✗ Incorrect
When interfaces are merged, a required property overrides an optional one with the same name and type. So 'x' is required number in C.