-
-
Notifications
You must be signed in to change notification settings - Fork 261
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
Fix IntrinsicAttributes error in TypeScript definitions #304
Comments
If the "Strongly Typed Svelte Component Interface" RFC is accepted and implemented in the language tools, writing component library definitions should be a lot easier. Attempting to auto-generate definitions may work on the surface for props/slots but is untenable in the long run. Especially since it's not the official way, it's prone to breakage if the internal API changes. |
Hello. Is there any update on this issue? Would be happy to help adding |
@semenodp I'm rewriting the types, but I don't want this to block anybody in the meantime. I'd welcome a PR of adding the |
@semenodp I've uploaded what I currently have in PR #385 A component props definition must extend its semantic HTML attributes ONLY if class Tag {
$$prop_def: svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["span"]> & {
// ...
}
} As a result, the following should work (no errors from the VS Code Svelte Language Server extension or from svelte-check). <!-- the "class", "style" attributes should not cause an error -->
<Tag
class="class-name"
style="color: red;"
type="red"
on:click="{(e) => {
console.log(e); // MouseEvent
}}"
>
text
</Tag>
<TagSkeleton class="class-name" style="color: red;" /> Currently, the "class", "style" attributes will cause an error, and the |
@semenodp The rewritten TypeScript definitions are released in v0.23. Notable changes
Tests that validate the TS definitions are located in the tests folder. There should be no errors when running Also, for anyone reading this in the future: I walk back what I said about manually maintaining type definitions. They should be auto-generated along with the COMPONENT_INDEX.md and COMPONENT_API.json |
This error has appeared several times now: #253, #300, #303
Component props should be typed as the intersection of the semantic element props and props exported from the component.
Furthermore, potentially adding
{ [key: string]: any; }
can serve as a catch-all for custom component attributes. A common use case would bedata-{X}
selectors used for testing/analytics.For example, the following should not throw a TS error:
The
data-test
andstyle
attributes are not explicitly defined in the Link component, but they should still be valid.The text was updated successfully, but these errors were encountered: