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
Dynamic property name
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;
}Extend interface
Override interface
You can also override an interface by replacing the way a given prop is defined
Ask typescript to ignore an error
Object vs object vs {}
Last updated
Was this helpful?