diff --git a/types/toastr/index.d.ts b/types/toastr/index.d.ts index f3e069bb2305ab..1e598539dbc78e 100644 --- a/types/toastr/index.d.ts +++ b/types/toastr/index.d.ts @@ -355,7 +355,7 @@ interface Toastr { subscribe: (callback: (response: ToastrResponse) => void) => void; } -declare var toastr: Toastr; -declare module "toastr" { - export = toastr; -} +declare const toastr: Toastr; + +export = toastr; +export as namespace toastr; diff --git a/types/toastr/toastr-global-module-tests.ts b/types/toastr/toastr-global-module-tests.ts new file mode 100644 index 00000000000000..1000bb664a5640 --- /dev/null +++ b/types/toastr/toastr-global-module-tests.ts @@ -0,0 +1,10 @@ +// This file has no imports, so use a dummy export to mark this file as a module. +export {}; + +// @ts-expect-error - UMD global usage should be prohibited inside modules +toastr.success("Module files should import toastr explicitly."); + +// Explicit global access remains available for script-tag consumers. +const globalToast: JQuery = globalThis.toastr.success("The UMD value is available on the global object."); +globalThis.toastr.options.closeButton = true; +globalThis.toastr.clear(globalToast); diff --git a/types/toastr/toastr-tests.ts b/types/toastr/toastr-tests.ts index d60490d97677b9..1038abd1a6a596 100644 --- a/types/toastr/toastr-tests.ts +++ b/types/toastr/toastr-tests.ts @@ -1,3 +1,7 @@ +import toastr = require("toastr"); + +type ToastrOptions = typeof toastr.options; + declare let displayMethodStr: "success" | "info" | "warning" | "error"; declare let undefinedVal: undefined; declare let booleanVal: boolean; diff --git a/types/toastr/tsconfig.json b/types/toastr/tsconfig.json index 6312e5a61cd42f..431989aa24e078 100644 --- a/types/toastr/tsconfig.json +++ b/types/toastr/tsconfig.json @@ -15,6 +15,7 @@ }, "files": [ "index.d.ts", - "toastr-tests.ts" + "toastr-tests.ts", + "toastr-global-module-tests.ts" ] }