introduce types.ts; improve types for internal functions with focus on hx-swap#2107
introduce types.ts; improve types for internal functions with focus on hx-swap#2107JLarky wants to merge 4 commits intobigskysoftware:devfrom
Conversation
| | "afterend" | ||
| | "delete" | ||
| | "none"; | ||
|
|
There was a problem hiding this comment.
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.
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.tsbased on code form @trvswgnr https://gist.github.com/trvswgnr/7239fa78cd12cee986384623a29b9b89anys but it's better than nothing :)test-typesfrom 21 to 15internalAPI(the ones that @trvswgnr wrote)This PR will introduce a new file
dist/types.tsinto the mix, I'm not 100% sure if that's good or bad :)So let's talk a bit about alternatives:
.jsfile with jsdoc syntax --- that's what we were doing so far, not the best ergonomicshtmx.d.ts--- that works great for external types likeHtmxConfigorhtml.addClass, but you don't want to putsplitOnWhitespacetheretypes.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.jsandsomething.d.tsfiletypes.ts--- that's what someone recommended to me to try instead of doing.d.tsand 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 takesHtmxInternalApias first argument, so that means thatHtmxInternalApikind of have to be public API now, and if we are adding types ofHtmxInternalApitohtmx.d.tsthen you have to add all additional types likeHtmxTriggerSpecificationorTriggerHandlerto it and so on.init(apiRef: import("./types").HtmxInternalApi): void;which works, but sends a signal that "there will be dragons"src/types.tsshould 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
masterfor website changes,devforsource changes)
approved via an issue
npm run test) and verified that it succeeded