Another approach is:
error(message: string, options?: {title?: string, autoHideAfter?: number});
So when you want to omit the title parameter, just send the data like that:
error('the message', { autoHideAfter: 1 })
I'd rather this options because allows me to add more parameter without having to send the others.
You can also use Partial<T>
type in method's signature but it this case you have to create an interface for your options:
interface IMyOptions {
title: string;
autoHideAfter: number;
}
And then the method's signature can look like:
error(message: string, options?: Partial<IMyOptions>);
Usage is the same as above.
Type Partial<T>
should already be declared in global typings as following:
type Partial<T> = {
[P in keyof T]?: T[P];
};