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

Convert to arrow function loses generic type #43

Open
chrisj-back2work opened this issue Jan 23, 2022 · 1 comment
Open

Convert to arrow function loses generic type #43

chrisj-back2work opened this issue Jan 23, 2022 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@chrisj-back2work
Copy link

Thank you for a very helpful tool.

Today I found a problem when the refactor target uses generics.

Original code --

function isEnumKey<T extends Enum>(enumSrc: T, key: unknown): key is keyof T {
  return Number.isInteger(enumSrc[key as keyof T])
}

Refactored using "Convert to arrow function" --

const isEnumKey = (enumSrc: T, key: unknown): key is keyof T => {
  return Number.isInteger(enumSrc[key as keyof T])
}

... which results in Cannot find name 'T'. ts(2304)

What the refactor should result in --

const isEnumKey = <T extends Enum>(enumSrc: T, key: unknown): key is keyof T => {
  return Number.isInteger(enumSrc[key as keyof T])
}

Does JavaScript Booster have a way to verify if a refactor introduces a compile error?

@xsburg
Copy link
Owner

xsburg commented Jan 24, 2022

Thank you for reporting the issue. It's clearly an uncovered scenario that should be fixed.

In general, JavaScript Booster uses Babel to manipulate code, which prevents syntax errors but cannot prevent semantic errors as above. There are normally two sorts of bugs that might arise in such an approach: the code action shouldn't be available in a certain scenario (therefore the trigger code should be fixed); the code action doesn't work as expected (we need to fix the action logic and support the scenario).

@xsburg xsburg added bug Something isn't working good first issue Good for newcomers labels Jan 24, 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 good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants