如何在省略一些其他可选参数的同时传递可选参数? [英] How to pass optional parameters while omitting some other optional parameters?
本文介绍了如何在省略一些其他可选参数的同时传递可选参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定以下签名:
export interface INotificationService {
error(message: string, title?: string, autoHideAfter?: number);
}
如何调用函数 error()
不 指定 title
参数,而是将 autoHideAfter
设置为说1000
?
How can I call the function error()
not specifying the title
parameter, but setting autoHideAfter
to say 1000
?
推荐答案
如文档,使用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);
这篇关于如何在省略一些其他可选参数的同时传递可选参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文