Advertisement
Advanced TypeScript, Namespaces & Declaration Merging

What conflicts and restrictions exist when merging two interfaces that both declare the same property name?

Short answer

If both interface declarations declare the SAME property name with the SAME type, they merge without conflict; if they declare it with DIFFERENT, incompatible types, TypeScript raises a compile error — merging only works cleanly when the overlapping members are structurally…

Save TypeScript mock interview
Advertisement
AModel answer
If both interface declarations declare the SAME property name with the SAME type, they merge without conflict; if they declare it with DIFFERENT, incompatible types, TypeScript raises a compile error — merging only works cleanly when the overlapping members are structurally compatible across all declarations.
interface Config { timeout: number; }
interface Config { timeout: number; retries: number; } // OK, 'timeout' matches
// interface Config { timeout: string; } // Error: subsequent property declaration must be of type 'number'
Real-world example
Debugging a confusing 'subsequent property declarations must have the same type' error when two teams accidentally declare overlapping global interfaces differently.
Likely follow-ups
  • How does interface merging handle overlapping METHOD signatures rather than plain properties, in terms of overload ordering?
Related topics