0

Bootboxでカスタムダイアログを使用しようとしていますbootbox.d.ts。コンパイルに失敗します。

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 にタイプ '文字列' を適用できませんでした。ボタン: { キャンセル: { ラベル: 文字列; クラス名: 文字列; }; confirmDelete: { ラベル: 文字列; クラス名: 文字列; コールバック: () => 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;
}

使用しているパラメーターでダイアログを受け入れるように定義を変更するにはどうすればよいですか?

4

2 に答える 2

0

整理しました。行を追加する必要がありました

dialog(options: any): void; // Had to add this line

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;
    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; }
于 2014-02-10T11:16:45.537 に答える
0

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");
      }
    }
  }]
 );
于 2014-02-10T13:52:40.887 に答える