sindresorhus/eslint-plugin-unicorn

prefer-set-has doesn't autofix types

Open

#1,148 创建于 2021年3月24日

在 GitHub 查看
 (1 评论) (1 反应) (0 负责人)JavaScript (5,022 star) (468 fork)user submission
enhancementhelp wanted

描述

When "autofixing" an array to a set, the type definition should be fixed too (or the fix should be skipped).

prefer-set-has

const a: Array<'foo' | 'bar'> = ['foo', 'bar']

for (let i = 0; i < 3; i++) {
  if (a.includes(someString)) {
    console.log(123)
  }
}

This is corrected to:

const a: Array<'foo' | 'bar'> = new Set(['foo', 'bar'])

for (let i = 0; i < 3; i++) {
  if (a.has(someString)) {
    console.log(123)
  }
}

Which is confusing and wrong.

贡献者指南