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

TypeScript spell check suggesting generated variable for undeclared component #1726

Closed
jasonlyu123 opened this issue Nov 22, 2022 · 4 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@jasonlyu123
Copy link
Member

jasonlyu123 commented Nov 22, 2022

Describe the bug

This only happens in the new transformation because the suggested variable only exists to check if the variable is a valid component. This seems to be related to how similar the generated variable is to the original component name. So the longer the name of the component, the lower the percentage of the prefix and suffix.

Reproduction

<script lang="ts"></script>

<MyLongComponent />

Expected behaviour

  1. The error should be "Cannot find name 'MyLongComponent'" but is "Cannot find name 'MyLongComponent'. Did you mean '$$_MyLongComponent0C' ?".
  2. The quick fix for it should be to import a component with the same name but it's "Change spelling to $$_MyLongComponent0C"

System Info

  • OS: Windows
  • IDE: VSCode

Which package is the issue about?

svelte2tsx svelte-language-server

Additional Information, eg. Screenshots

No response

@jasonlyu123 jasonlyu123 added the bug Something isn't working label Nov 22, 2022
@jasonlyu123
Copy link
Member Author

jasonlyu123 commented Nov 23, 2022

It seems like if we suffix the variable with an equal number of nonsense characters. like $$_MyLongComponent0C$$$$$$$$$$$$$$$$. TypeScript would stop saying the undeclared variable is a misspelling of the generated variable 😅

@dummdidumm
Copy link
Member

dummdidumm commented Nov 23, 2022

mhm that's unfortunate. Alternatives I can think of:

  • change the name completely to something like $$_1_0 where 1 is taking out of some componentname->number map ({ MyLongComponent: 1, ... })?
  • Reverse the component name (tnenopmoCgnoLyM)

@jasonlyu123
Copy link
Member Author

Reverse the name works. I also tried repeating the name twice to MyLongComponetMyLongComponent which also works. Which one do you prefer?

@dummdidumm
Copy link
Member

I vote for reversing

dummdidumm pushed a commit that referenced this issue Nov 29, 2022
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Nov 29, 2022
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.
Projects
None yet
Development

No branches or pull requests

2 participants