I have the following interface
interface ErrorHandler {
[key: string]: string;
}
And I use it like this
let errorHandler: ErrorHandler = {
name: "Your name cannot be empty",
email: "Enter a valid email address",
birthday: "You are too young"
};
function postData(data: any, errorHandler: ErrorHandler){
// ...
}
postData(someData, errorHandler);
That's good for now. But, say you want the errorHandler object have a function named handler. How would you declare the interface?
For example, you want your errorHandler be like this:
let errorHandler: ErrorHandler = {
name: "Your name cannot be empty",
email: "Enter a valid email address",
birthday: "You are too young",
handler: (message: string) => alert(message)
};