vscode-javascript-booster
vscode-javascript-booster copied to clipboard
Convert to arrow function loses generic type
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?
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).