dusk-network / dusk-network/duskit
fix(svelte-actions): resolve JSDoc type inference failure for `outsideclick` event in pure JS components
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 2
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Context
We recently implemented a highly robust, strictly typed outsideClick action in the @duskit/svelte-actions package. The type contract uses a generic to accurately infer the currentTarget based on the DOM node it is attached to, and enforces the presence of a destroy method.
For consumers using <script lang="ts">, the developer experience is flawless: the outsideclick event payload is perfectly inferred. However, for consumers using standard JavaScript (<script>) relying on Svelte's language server (Svelte2tsx) and JSDoc, the evt parameter in inline handlers degrades to an implicit any.
The Root Cause
Svelte2tsx's parser struggles to resolve complex generics and type intersections (e.g., ActionReturn<...> & { destroy: () => void }) when extracting event types from actions in JS files. Instead of resolving the signature, it panics and falls back to any.
Failed Attempts (The Graveyard)
To prevent future developers from wasting time on the same rabbit holes, here is what we already tried:
- Inline Intersection (
ActionReturn & { destroy }): This was the initial approach. Svelte2tsx completely failed to extract the custom attributes, leading to theanytype. - Interface Extension: We tried explicitly extending the
ActionandActionReturninterfaces to hide the intersection from the parser. The language server ignored the strict return type and the issue persisted. - Global Namespace Pollution (
svelte/elements+HTMLElementEventMap): We attempted the "nuclear option" by declaring the event globally so the editor would recognize it everywhere.- The tragic irony: It worked perfectly, until the
use:outsideClickdirective was added to the element. Svelte2tsx prioritizes the action's return type over global definitions. As soon as it read our action, it got confused by the generics again, overwrote the global definition, and poisoned the template withany. - We could have fixed this for JS by stripping the event definition from the action's return type, but this would have broken the strict contract for pure TS consumers and higher-order components. We refused to compromise the library's architectural integrity to appease a faulty parser.
- The tragic irony: It worked perfectly, until the
Current Status & Goal
We have reverted to the strict, pure TS definition. The single source of truth remains pristine.
This issue is open to track potential upstream fixes in Svelte2tsx or to find a creative JSDoc workaround that restores full type inference for JS consumers without castrating the TypeScript contract.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the strict outsideClick action in the @duskit/svelte-actions package and reproduce the inline-handler inference failure in a pure JavaScript Svelte component using Svelte's language server. Review the documented failed approaches and investigate Svelte2tsx handling of the action's generic return type. Done means restoring the outsideclick event's inferred evt type for JavaScript consumers without weakening the TypeScript contract.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- developer-experience, frontend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100