snippettypescriptCritical
How to pass optional parameters while omitting some other optional parameters?
Viewed 0 times
whilehowsomeotheroptionalomittingparameterspass
Problem
Given the following signature:
How can I call the function
export interface INotificationService {
error(message: string, title?: string, autoHideAfter?: number);
}How can I call the function
error() not specifying the title parameter, but setting autoHideAfter to say 1000?Solution
As specified in the documentation, use
Playground link.
undefined:export interface INotificationService {
error(message: string, title?: string, autoHideAfter? : number);
}
class X {
error(message: string, title?: string, autoHideAfter?: number) {
console.log(message, title, autoHideAfter);
}
}
new X().error("hi there", undefined, 1000);Playground link.
Code Snippets
export interface INotificationService {
error(message: string, title?: string, autoHideAfter? : number);
}
class X {
error(message: string, title?: string, autoHideAfter?: number) {
console.log(message, title, autoHideAfter);
}
}
new X().error("hi there", undefined, 1000);Context
Stack Overflow Q#30734509, score: 549
Revisions (0)
No revisions yet.