quick-lint / quick-lint-js

quick-lint-js finds bugs in JavaScript programs
https://quick-lint-js.com
GNU General Public License v3.0
1.52k stars 191 forks source link

9$: warn on 'keyof T[]' in type #1218

Open strager opened 3 months ago

strager commented 3 months ago

In a TypeScript type, keyof T[] is the same as number (I think). The user likely meant (keyof T)[]. We should emit a warning, telling them to write either number or add parentheses.

Inspired by this article: https://www.totaltypescript.com/array-types-in-typescript

Using keyof with T[] can lead to unexpected results.

const result: keyof Person[] = ["id", "name"];