htmx
htmx copied to clipboard
Declare global and window types
I am having a hard time declaring htmx types globally and on the window object. I load htmx via a script tag in the browser, but I would still like to have type-safety inside my typescript web-components.
Here are my attempts in globals.d.ts:
import * as Htmx from "htmx.org/dist/htmx.d.ts";
import Htmx from "htmx.org/dist/htmx.d.ts";
import Htmx from "htmx.org";
declare global {
type htmx = Htmx;
interface Window {
htmx: Htmx;
}
}
I think this has to do with the way .d.ts files are generated. Something to do with namespaces... But I have no idea how to make it work
Try this:
import * as Htmx from 'htmx.org'
declare global {
interface Window {
htmx: typeof Htmx
}
}
Thanks to @i7N3, I also got the global htmx working:
import * as Htmx from 'htmx.org';
declare global {
var htmx: typeof Htmx;
interface Window {
htmx: typeof Htmx;
}
}