Skip to content
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

Not all svg attributes exist when using typescript #387

Closed
sorig opened this issue Jul 30, 2020 · 3 comments
Closed

Not all svg attributes exist when using typescript #387

sorig opened this issue Jul 30, 2020 · 3 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release. good first issue Good for newcomers

Comments

@sorig
Copy link

sorig commented Jul 30, 2020

Describe the bug
When using typescript, role and tabIndex do not exist on svg elements. This leads me to believe that the jsx type declaration file is outdated.

To Reproduce

  1. Set up a fresh typescript svelte project
npx degit sveltejs/template svelte-typescript-app
cd svelte-typescript-app
node scripts/setupTypeScript.js
  1. Replace the contents of src/App.svelte with:
<script lang="ts">
</script>

<main tabindex={0}>
	<svg tabIndex={0} viewBox="0 0 10 10" width="10" height="10">
		<g tabindex={0}></g>
		<g role="button"></g>
		<g xlink:role="button"></g>
		<g aria-roledescription="asdf"></g>
	</svg>
</main>
  1. npm run validate returns the following errors:
/████/svelte-typescript-app/src/App.svelte:5:7
Error: Type '{ tabindex: number; viewBox: string; width: string; height: string; }' is not assignable to type 'SVGProps<SVGSVGElement>'.
  Property 'tabindex' does not exist on type 'SVGProps<SVGSVGElement>'. (ts)
0}>
        <svg tabIndex={0} viewB

/████/svelte-typescript-app/src/App.svelte:6:6
Error: Type '{ tabindex: number; }' is not assignable to type 'SVGProps<SVGGElement>'.
  Property 'tabindex' does not exist on type 'SVGProps<SVGGElement>'. (ts)
10">
                <g tabindex={0}></g>


/████/svelte-typescript-app/src/App.svelte:7:6
Error: Type '{ role: string; }' is not assignable to type 'SVGProps<SVGGElement>'.
  Property 'role' does not exist on type 'SVGProps<SVGGElement>'. (ts)
</g>
                <g role="button">

Expected behavior
I would expect svelte with typescript to have out-of-the-box support for standard SVG attributes. Note that xlink:role works, but it seems to me that the svg standard prefers role instead of xlink:role.

I added aria-roledescription in my example just to check whether this applies to all aria attributes. That is not the case.

System (please complete the following information):

  • OS: macOS 10.13.6
  • IDE: VSCode
  • Plugin/Package: "Svelte for VSCode" and "svelte-check"
@sorig sorig added the bug Something isn't working label Jul 30, 2020
@dummdidumm dummdidumm added the good first issue Good for newcomers label Jul 30, 2020
dummdidumm added a commit that referenced this issue Aug 4, 2020
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Aug 4, 2020
@sorig
Copy link
Author

sorig commented Aug 11, 2020

Thanks for sorting this @dummdidumm ! role works now but I still get the error for tabIndex and crossOrigin. Could it have something to do with the camelCase? Note, the error occurs with both camelcase and all lower case spellings.

To reproduce: same steps as above.

@dummdidumm
Copy link
Member

Thanks for the info, it's because it's written in camel case in the svelte-jsx.d.ts file, we must change it to all-lowercase. Doing this now.

dummdidumm added a commit that referenced this issue Aug 11, 2020
tabindex / crossorigin -> lowercase
#387
@BrancuAlexandru
Copy link

Same thing applies for the isolation and dataname attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release. good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants