0
0
Typescriptprogramming~5 mins

Multiple interface extension in Typescript - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Multiple interface extension
O(1)
Understanding Time Complexity

We want to understand how the time it takes to run code changes when using multiple interface extensions in TypeScript.

Specifically, how does combining interfaces affect the work the program does?

Scenario Under Consideration

Analyze the time complexity of the following code snippet.


interface A {
  methodA(): void;
}
interface B {
  methodB(): void;
}
interface C extends A, B {
  methodC(): void;
}

function useC(obj: C) {
  obj.methodA();
  obj.methodB();
  obj.methodC();
}
    

This code shows an interface C that extends two interfaces A and B, combining their methods. Then a function calls all methods from C.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: Calling three methods on the object.
  • How many times: Exactly three calls, no loops or recursion.
How Execution Grows With Input

Since the number of method calls is fixed, the work does not grow with input size.

Input Size (n)Approx. Operations
103
1003
10003

Pattern observation: The number of operations stays the same no matter how big the input is.

Final Time Complexity

Time Complexity: O(1)

This means the time to run the code stays constant regardless of input size.

Common Mistake

[X] Wrong: "Extending multiple interfaces makes the code slower as input grows."

[OK] Correct: The interface extension only combines method types; it does not add loops or repeated work, so execution time stays constant.

Interview Connect

Understanding how interface extension affects code helps you explain design choices clearly and shows you know how TypeScript structures work without adding hidden costs.

Self-Check

"What if the function useC called the methods inside a loop over an array of objects? How would the time complexity change?"