Module Augmentation

Module Augmentation is the process of extending type definitions by merging declarations from an existing module with your own type definitions. It is particularly useful when you want to modify interfaces from external packages. Such cases occur when type definitions from external packages are broken and need to be patched.

Example:

In the following example the existing definition for the Configuration from the webpack module gets extended by a property called devServer:

1
2
3
4
5
6
7
8
9
import type {Configuration} from 'webpack';

declare module 'webpack' {
interface Configration {
devServer: {
open: boolean;
};
}
}

Video Tutorial: