-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
introduce types.ts; improve types for internal functions with focus on hx-swap #2107
Conversation
| "afterend" | ||
| "delete" | ||
| "none"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably add (string & NonNullable<unknown>)
like this:
export type SwapStyle =
| "innerHTML"
| "outerHTML"
| "afterbegin"
| "beforebegin"
| "afterend"
| "beforeend"
| "none"
| "delete"
| (string & NonNullable<unknown>);
because there are other swap styles (like morph:innerHTML
when using idiomorph)
this way, editor autocomplete will still be there for known values, but any string can be passed.
you can add me as co-author on this 😘
|
will do :) do you have any thoughts on |
i think that devs authoring their own extensions will usually do so in their own environment and not as part of the htmx project (at least initially), so it would make sense that those types are exposed somehow. "internal api" is a little misleading, as it gets used throughout extensions, making it more of a "developer api". the only reason i would be for .d.ts instead of .ts is that the latter might lead people to believe that there is logic in there. |
threshold?: string; | ||
delay?: number; | ||
pollInterval?: number; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looked through and updated this with keys found in source:
export interface HtmxTriggerSpecification {
trigger: string;
sseEvent?: string;
eventFilter?: string;
changed?: boolean;
once?: boolean;
consume?: boolean;
from?: string;
target?: string;
throttle?: number;
queue?: string;
root?: string;
threshold?: string;
delay?: number;
pollInterval?: number;
};
Hey all, we're about to do a pretty significant refactor and unfortunately now isn't the right time to introduce this. The htmx typing story is at the moment incomplete—if you want to update the API types you're more than welcome to. |
@alexpetros I need a bit more guidance here :) |
Haha the guidance is, for the moment, please hold off on TS changes. EDIT: unless they're to the type declarations in the API interface. |
Description
HtmxExtension.init type
(src/htmx.d.ts)src/types.ts
based on code form @trvswgnr https://gist.github.com/trvswgnr/7239fa78cd12cee986384623a29b9b89any
s but it's better than nothing :)test-types
from 21 to 15internalAPI
(the ones that @trvswgnr wrote)This PR will introduce a new file
dist/types.ts
into the mix, I'm not 100% sure if that's good or bad :)So let's talk a bit about alternatives:
.js
file with jsdoc syntax --- that's what we were doing so far, not the best ergonomicshtmx.d.ts
--- that works great for external types likeHtmxConfig
orhtml.addClass
, but you don't want to putsplitOnWhitespace
theretypes.d.ts
--- this is what SvelteKit is doing and I first started with that approach when I started doing JsDoc projects, but I found it a bit clumsy, the biggest issue for me was how confusing it would work in case if you have bothsomething.js
andsomething.d.ts
filetypes.ts
--- that's what someone recommended to me to try instead of doing.d.ts
and I was happy ever since :D (but I'm not married to that)So most of this PR is done, there are two outstanding things that I wanted to discuss before I turn this PR from Draft to Ready:
HtmxExtension.init
--- this method takesHtmxInternalApi
as first argument, so that means thatHtmxInternalApi
kind of have to be public API now, and if we are adding types ofHtmxInternalApi
tohtmx.d.ts
then you have to add all additional types likeHtmxTriggerSpecification
orTriggerHandler
to it and so on.init(apiRef: import("./types").HtmxInternalApi): void;
which works, but sends a signal that "there will be dragons"src/types.ts
should actually be inhtmx.d.ts
? In the original gist it feels like it was intended to be a part of public api https://gist.github.com/trvswgnr/7239fa78cd12cee986384623a29b9b89Testing
Checklist
master
for website changes,dev
forsource changes)
approved via an issue
npm run test
) and verified that it succeeded