Skip to content

Javascript Keywords as Props - Error #152

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

Closed
jvanderen1 opened this issue Dec 19, 2021 · 1 comment · Fixed by #159
Closed

Javascript Keywords as Props - Error #152

jvanderen1 opened this issue Dec 19, 2021 · 1 comment · Fixed by #159

Comments

@jvanderen1
Copy link

There seems to be a re-occurring issue where you cannot properly use props which are named the same as Javascript keywords (i.e. class, for, etc.). It seems the best workaround is to simply use the $$props syntax.

In my case, I am trying to the use for and class prop inside my reusable label component:

<label for={$$props.for} class={`block text-sm font-medium text-gray-700 ${$$props.class}`}>
  <slot />
</label>

However, when running eslint ., I received the following error on both these guys:

  1:13  error  '$$props' is not defined  no-undef
  1:76  error  '$$props' is not defined  no-undef

However, if I add the <script> tags at the top of the file, like so:

<script></script>

<label for={$$props.for} class={`block text-sm font-medium text-gray-700 ${$$props.class}`}>
	<slot />
</label>

I receive no errors.

I am not sure what the svelte team can do as this seems like a language oversight, but I wish there was a way to easily extract these Javascript keyword-named props.

@jvanderen1 jvanderen1 changed the title Props as Keywords Errors Javascript Keywords as Props - Error Dec 19, 2021
@dummdidumm
Copy link
Member

Possible duplicate of #148

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants