Skip to content

Convert to arrow function loses generic type #43

Description

@chrisj-back2work

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions