Dmytro Morar
TypeScript

Declaration merging

TypeScript can merge multiple declarations with the same name into one type. This is common for interfaces, namespaces, and namespace augmentation for functions/classes.

Interface merge

interface User {
  id: number;
}
interface User {
  name: string;
}
const person: User = { id: 1, name: "Anna" };

Namespace + function

function greet(name: string) {
  return `Hello, ${name}`;
}
namespace greet {
  export const version = "1.0";
}
greet.version;

Extending globals

interface Window {
  myCustomVar: string;
}

On this page