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

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

Open
strager opened this issue Apr 27, 2024 · 0 comments
Open

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

strager opened this issue Apr 27, 2024 · 0 comments
Labels
for hire Get paid for working on this task: https://quick-lint-js.com/hiring.html

Comments

@strager
Copy link
Collaborator

strager commented Apr 27, 2024

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"];
@strager strager added the for hire Get paid for working on this task: https://quick-lint-js.com/hiring.html label Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for hire Get paid for working on this task: https://quick-lint-js.com/hiring.html
Projects
None yet
Development

No branches or pull requests

1 participant