Skip to content

"Convert parameters to destructured object": enable for functions with just one parameter #41753

Closed
@OliverJAsh

Description

@OliverJAsh

Search Terms

Suggestion

Back when this refactor was added in #30089, it was decided that the refactor would not be available for functions with less than 2 parameters.

The refactor will not be available on:

  • functions with less than 2 parameters

#30089 (comment)

I would like to suggest that this refactor should be available for functions with just one parameter.

Use Cases

The reason is because I often use this refactoring to make a function into a React component (which always receive their parameters aka props as an object), and it's not infrequent that I need to do this for a function that receives just one parameter.

Furthermore, it would be useful to run this refactoring if you plan to add more parameters immediately afterwards—as opposed to adding more parameters and then converting to an object.

Examples

declare const add: (n1: number, n2: number) => number;

const fn = (a: number) => add(a, 1);

should convert to

declare const add: (n1: number, n2: number) => number;

const fn = ({ a }: { a: number }) => add(a, 1);

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CommittedThe team has roadmapped this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions