Typescript recipes

Add any properties to an interface

By default, interfaces not allows other properties that those specified.

You can however allow custom properties by using the [key: string]: any; in an interface

interface Post {
title: string;
visible: boolean;
// Allows any type
[key: string]: any;
}

You can also extend an existing interface

Original interface

interface Post {
title: string;
visible: boolean;
}

Extendable interface

interface PostExtended extends Post {
[key: string]: any;
}