Skip to content

Add a refactoring that annotates an implicit or explicit any with a best guess type inferred from its use sites #13243

Open
@aluanhaddad

Description

@aluanhaddad

I would very much appreciate having a codefix (refactoring) that, given an explicit any annotation, offers to change it to an {} annotation.

For example, given

function log(x: any) {
  console.log(x);
}

a code fix would be offered to change the declared type of x to {} resulting in

function log(x: {}) {
  console.log(x);
}

However, given

function log(x: any) {
  console.log(x.name);
}

a code fix would be offered to change the declared type of x to { name: any } resulting in

function log(x: {name: any}) {
  console.log(x);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    CommittedThe team has roadmapped this issueDomain: Quick FixesEditor-provided fixes, often called code actions.SuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions