-
-
Notifications
You must be signed in to change notification settings - Fork 207
data-
attributes should be allowed on components that wrap HTML elements
#1825
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
Comments
This would be amazing, I just hit this problem now |
This seems to be an issue when using svelte actions (directives-like?) and binding custom events on the target element. App compiles fine but vs-code marks it as an error. |
For a library, users or library authors can enhance this in the userland for now. declare module 'svelte/elements' {
interface HTMLAttributes<T> {
[x:`data-${string}`]: any;
}
} But this only work in the manually typed component because of another problem. In our generated code, we use spread for merging props and |
Thanks for digging into that! While doing the Svelte PR which changes this in core I was wondering why intellisense wasn't forwarding it. Since it's only possible to add an index signature to the props interface by using |
We now have svelte 4 stable version released. Can this be progressed please? It's currently blocking our upgrade. |
Minimum reproducible for the issue: interface Foo {
x?: true;
[key: `data-${string}`]: any;
}
const foo: Foo = {
'data-x': true // works
};
const destructured = {... {} as Foo, ...{} as {} }
const bar: typeof destructured = {
'data-x': true // fails
} It seems that TS does not use index signatures as soon as two separate things are spread onto the same object. But that's what we're doing under the hood for intellisense generation of the prop type. So we need to change that to something else. |
Using a type union instead of spread, because the latter does remove index signatures from the resulting type #1825
Using a type union instead of spread, because the latter does remove index signatures from the resulting type #1825
Hey @dummdidumm, is the If I manually edit the Minimal reproduction where the only thing I'm specifying as the prop types is that template lit: |
Disregard - in the process of creating a repro repo, we realized something in our lockfile was hanging on to an older version of svelte2tsx for dear life! |
Description
produces
The error is legitimate since indeed the types for the carbon Button component do not include data-cy. But the Button component does forward it to the HTML button through
...$$restProps
, anddata-
attributes are valid for html elements.Proposed solution
Best is probably to add an index signature to the html typings in
svelte/elements
which looks like this:... but we can't do that until Svelte 4 because Svelte 3 has a minimum version requirement on a TS version that doesn't have that feature yet.
Maybe it's possible to add that inside svelte2tsx in the meantime.
Alternatives
No response
Additional Information, eg. Screenshots
No response
The text was updated successfully, but these errors were encountered: