How to extend interfaces declared in external libraries in Typescript

Typescript allows us to easily extend types by using module augumentation. 

Let's take a look at one quick example - extending the React Material Ui Library Theme.

All we need to do is create a file ending in *`.d.ts`* at the root of our Typescript project - in this case I'll name it **`material-ui.d.ts`**:

import {
  Theme as MuiTheme,
} from '@mui/material/styles';

declare module '@mui/material/styles' {
  export interface Theme extends MuiTheme {
    customization?: Record<string, string>;

Denisa Halmaghi
07 Dec 2021
« Back to post