feat: custom component attributes via svelteHTML.ComponentAttributes#3060
Open
khromov wants to merge 2 commits into
Open
feat: custom component attributes via svelteHTML.ComponentAttributes#3060khromov wants to merge 2 commits into
khromov wants to merge 2 commits into
Conversation
….ComponentAttributes Allow declaring extra namespaced attributes (e.g. <MyComponent mochi:defer />) on any Svelte component through a d.ts augmentation, with the values type-checked against the declared types and undeclared namespaced attributes reported as errors. - svelte2tsx: route colon-namespaced attributes on components through a new __sveltets_2_componentAttr helper whose parameter is the augmentable svelteHTML.ComponentAttributes interface (added to both shim sets). - Tests: htmlx2jsx fixture + language-server diagnostics fixture. - Docs + changeset.
Rename the example namespace from mochi: to a generic custom: across docs, the changeset, shim doc-comments, and the svelte2tsx/language-server fixtures (inputs and regenerated snapshots).
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.
Frameworks built on top of Svelte sometimes attach custom namespaced attributes to components (e.g.
<MyComponent custom:defer />). Until now these triggered type errors because the attribute isn't part of the component's props.You can now declare such attributes globally — and have their values type-checked — by augmenting the
svelteHTML.ComponentAttributesinterface in ad.tsfile (e.g. yourapp.d.ts):With this in place:
:are treated as custom component attributes.How it works
svelte2tsxroutes colon-namespaced attributes on components through a new__sveltets_2_componentAttrhelper whose parameter is the augmentablesvelteHTML.ComponentAttributesinterface (added to both shim sets).Includes docs, a changeset, and htmlx2jsx + language-server diagnostics fixtures.