-
-
Notifications
You must be signed in to change notification settings - Fork 221
Closed
Labels
FixedFixed in master branch. Pending production release.Fixed in master branch. Pending production release.feature requestNew feature or requestNew feature or request
Description
Description
<script lang="ts">
import { Button } from 'carbon-components-svelte';
</script>
<Button on:click={() => alert('do thing')} data-cy={'forwarded-to-html-button'}>Button</Button>
produces
Error: Type '{ "data-cy": string; }' is not assignable to type 'ButtonProps'.
Object literal may only specify known properties, and '"data-cy"' does not exist in type 'ButtonProps'. (ts)
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
, and data-
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:
interface HTMLAttributes {
[key: `data-${string}`]: any;
}
... 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
BeeMargarida, alf5, willnationsdev, Myphz and Carlos-err406
Metadata
Metadata
Assignees
Labels
FixedFixed in master branch. Pending production release.Fixed in master branch. Pending production release.feature requestNew feature or requestNew feature or request