Skip to content

Rule proposal: no explicit array method callback argument types #11863

@ipanasenko

Description

@ipanasenko

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
  • My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

Hello.

I see from time to time people add types to array methods callback arguments manually, e.g.:

items.forEach((item: Item) => {})

I think this is pretty much redundant, because TS knows the type of item.

I'm not sure if this should be a new rule, or an update to an exisiting one (couldn't figure out which one would suit best though).

Fail Cases

items.forEach((item: Item) => {
  console.log(item.foo);
})

items.filter((item: Item) => item.foo === 'bar')

Pass Cases

items.forEach((item) => {
  console.log(item.foo);
})

items.filter((item) => item.foo === 'bar')

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: new plugin ruleNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions