TypeScript中的bootbox.dialog编译错误
我正在尝试使用Bootbox.d.ts创建用户Bootbox自定义对话框。它无法编译TypeScript中的bootbox.dialog编译错误,typescript,bootbox,Typescript,Bootbox,我正在尝试使用Bootbox.d.ts创建用户Bootbox自定义对话框。它无法编译 bootbox.dialog({ message: "I am a custom dialog", buttons: { success: { label: "Success!", className: "btn-success", callback: function() { Example.show("great success");
bootbox.dialog({
message: "I am a custom dialog",
buttons: {
success: {
label: "Success!",
className: "btn-success",
callback: function() {
Example.show("great success");
}
},
danger: {
label: "Danger!",
className: "btn-danger",
callback: function() {
Example.show("uh oh, look out!");
}
},
main: {
label: "Click ME!",
className: "btn-primary",
callback: function() {
Example.show("Primary button");
}
}
}
});
错误:
错误49提供的参数与调用的任何签名不匹配
目标:无法将类型“字符串”应用于类型为的参数1
{消息:字符串;按钮:{取消:{标签:字符串;类名:
string;};confirmDelete:{label:string;className:string;
回调:=>void;};};}
bootbox.d.ts:
interface BootboxStatic {
alert(message: string, callback: () => void): void;
alert(message: string, customButtonText?: string, callback?: () => void): void;
confirm(message: string, callback: (result: boolean) => void): void;
confirm(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: boolean) => void): void;
prompt(message: string, callback: (result: string) => void, defaultValue?: string): void;
prompt(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: string) => void, defaultValue?: string): void;
dialog(message: string, handlers: BootboxHandler[], options?: any): void;
dialog(message: string, handler: BootboxHandler): void;
dialog(message: string): void;
hideAll(): void;
animate(shouldAnimate: boolean): void;
backdrop(backdropValue: string): void;
classes(customCssClasses: string): void;
setIcons(icons: BootboxIcons): void;
setLocale(localeName: string): void;
addLocale(localeName: string, translations: BootboxLocale) : void;
}
interface BootboxStatic {
alert(message: string, callback: () => void): void;
alert(message: string, customButtonText?: string, callback?: () => void): void;
confirm(message: string, callback: (result: boolean) => void): void;
confirm(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: boolean) => void): void;
prompt(message: string, callback: (result: string) => void, defaultValue?: string): void;
prompt(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: string) => void, defaultValue?: string): void;
dialog(message: string, handlers: BootboxHandler[], options?: any): void;
dialog(message: string, handler: BootboxHandler): void;
dialog(message: string): void;
dialog(options: any): void; // Had to add this line
hideAll(): void;
animate(shouldAnimate: boolean): void;
backdrop(backdropValue: string): void;
classes(customCssClasses: string): void;
setIcons(icons: BootboxIcons): void;
setLocale(localeName: string): void;
addLocale(localeName: string, translations: BootboxLocale) : void; }
如何修改定义以接受使用参数的对话框?我已将其排序。必须添加行 dialogoptions:any:void;//必须加上这一行 到bootbox.d.ts:
interface BootboxStatic {
alert(message: string, callback: () => void): void;
alert(message: string, customButtonText?: string, callback?: () => void): void;
confirm(message: string, callback: (result: boolean) => void): void;
confirm(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: boolean) => void): void;
prompt(message: string, callback: (result: string) => void, defaultValue?: string): void;
prompt(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: string) => void, defaultValue?: string): void;
dialog(message: string, handlers: BootboxHandler[], options?: any): void;
dialog(message: string, handler: BootboxHandler): void;
dialog(message: string): void;
hideAll(): void;
animate(shouldAnimate: boolean): void;
backdrop(backdropValue: string): void;
classes(customCssClasses: string): void;
setIcons(icons: BootboxIcons): void;
setLocale(localeName: string): void;
addLocale(localeName: string, translations: BootboxLocale) : void;
}
interface BootboxStatic {
alert(message: string, callback: () => void): void;
alert(message: string, customButtonText?: string, callback?: () => void): void;
confirm(message: string, callback: (result: boolean) => void): void;
confirm(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: boolean) => void): void;
prompt(message: string, callback: (result: string) => void, defaultValue?: string): void;
prompt(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: string) => void, defaultValue?: string): void;
dialog(message: string, handlers: BootboxHandler[], options?: any): void;
dialog(message: string, handler: BootboxHandler): void;
dialog(message: string): void;
dialog(options: any): void; // Had to add this line
hideAll(): void;
animate(shouldAnimate: boolean): void;
backdrop(backdropValue: string): void;
classes(customCssClasses: string): void;
setIcons(icons: BootboxIcons): void;
setLocale(localeName: string): void;
addLocale(localeName: string, translations: BootboxLocale) : void; }
我会使用BootboxHandler数组
dialog(message: string, handlers: BootboxHandler[], options?: any): void;
interface BootboxHandler {
label: string;
class: string;
callback: (result?: any) => void;
}
更改您的代码:
bootbox.dialog("I am a custom dialog",
[{
label: "Success!",
class: "btn-success",
callback: function() {
Example.show("great success");
}
},
{
label: "Danger!",
class: "btn-danger",
callback: function() {
Example.show("uh oh, look out!");
}
},
{
label: "Click ME!",
class: "btn-primary",
callback: function() {
Example.show("Primary button");
}
}
}]
);