WIP (alpha): expose component events/slots, emit value+type default export#910
Draft
baseballyama wants to merge 1 commit into
Draft
Conversation
…t (alpha)
Final part of the importer-facing component type series. Emit the synthetic
default export as a value/type pair re-exported as default:
declare const $c: import('svelte').SvelteComponent<Props, Events, Slots>;
type $c = import('svelte').SvelteComponent<Props, Events, Slots>;
export { $c as default };
This fixes legacy `on:` event consumers: the parser references components via
`ComponentEvents<Foo>` (using `Foo` as a type), which the previous value-only
`export default` broke with TS2749 ("Foo refers to a value, used as a type").
`Events`/`Slots` are recovered from legacy `$$Events`/`$$Slots` when present, else
permissive. Props resolution via `ComponentProps<typeof Foo>` is unchanged. All
three synthetic statements are removed again in the restore pass (AST/scope
invariance suite stays green).
Experimental, alpha-stage, implemented by Claude Code.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 41fa3ef The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Warning
🚧 Work In Progress — Alpha. Do not merge.
Alpha-stage work authored by Claude Code (AI), published as a draft for early review only. Behavior/API may change or be dropped.
Note
Stacked on #909 (→ #908 → #907 → #906 → #905). Review the parents first.
What
PR 6 of 6 (final) — events / slots, plus a regression fix.
The regression this fixes
Investigating the consumer side showed the parser references an imported component's legacy events via
import('svelte').ComponentEvents<Foo>— usingFooas a type. But PRs #905–#909 emitted a value-onlyexport default <expr>, soFoohad no type meaning andComponentEvents<Foo>failed with:(For
bind:and slots, the consumer generates no component-type reference, so those need nothing on the producer side. Runes event props likeonclickalready flow throughComponentProps.)The fix
Emit the default export as a value + type pair, so
Fooworks as both:typeof Foo→ the value (SvelteComponent<…>) →ComponentProps<typeof Foo>✓ (props unchanged from WIP (alpha): emit component default export in virtual code for importer prop types #905–WIP (alpha): cover generic component prop types for importers #909)Fooas a type →ComponentEvents<Foo>/ComponentProps<Foo>✓ (no more TS2749)Events/Slotscome from legacy$$Events/$$Slotswhen declared, else permissiveRecord<string, any>(no spuriouson:/slot errors).This redesigns the emitted form from
Component<Props>to theSvelteComponentvalue/type pair, so the #905–#909 string-assertion tests are updated here to match (behavior/E2E tests are unchanged).Verified
8680 passing), incl. AST/scope invariance.$$Events/$$Slotswired in; export carries both value and type.tsctests: legacy$$Eventsevent detail resolves (CustomEvent<number>);Foousable as a type with no TS2749 even without$$Events.Series (complete)
$props()· WIP (alpha): synthesize legacyexport letprop types in virtual code #906export let· WIP (alpha): use legacy$$Propsinterface/type as prop types in virtual code #907$$Props· WIP (alpha): infer best-effort props type from un-annotated$props()#908 un-annotated inference · WIP (alpha): cover generic component prop types for importers #909 generics · this events/slots + value/type export🤖 Generated with Claude Code