From b7d011777e5d492eedeabd7cc7fddbe1324d4b62 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Thu, 3 Feb 2022 18:13:05 +0000 Subject: [PATCH] "Convert parameters to destructured object": enable for functions with just one parameter (#46945) * "Convert parameters to destructured object": enable for functions with just one parameter Fixes https://github.com/microsoft/TypeScript/issues/41753 * Add test --- .../refactors/convertParamsToDestructuredObject.ts | 2 +- ...cturedObject_arrowFunctionWithSingleParameter.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/refactorConvertParamsToDestructuredObject_arrowFunctionWithSingleParameter.ts diff --git a/src/services/refactors/convertParamsToDestructuredObject.ts b/src/services/refactors/convertParamsToDestructuredObject.ts index 784cefda23b..5fcd96a8018 100644 --- a/src/services/refactors/convertParamsToDestructuredObject.ts +++ b/src/services/refactors/convertParamsToDestructuredObject.ts @@ -1,7 +1,7 @@ /* @internal */ namespace ts.refactor.convertParamsToDestructuredObject { const refactorName = "Convert parameters to destructured object"; - const minimumParameterLength = 2; + const minimumParameterLength = 1; const refactorDescription = getLocaleSpecificMessage(Diagnostics.Convert_parameters_to_destructured_object); const toDestructuredAction = { diff --git a/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_arrowFunctionWithSingleParameter.ts b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_arrowFunctionWithSingleParameter.ts new file mode 100644 index 00000000000..5c130b3b0e9 --- /dev/null +++ b/tests/cases/fourslash/refactorConvertParamsToDestructuredObject_arrowFunctionWithSingleParameter.ts @@ -0,0 +1,13 @@ +/// + +////const foo = /*a*/(a: number)/*b*/ => { }; +////foo(1); + +goTo.select("a", "b"); +edit.applyRefactor({ + refactorName: "Convert parameters to destructured object", + actionName: "Convert parameters to destructured object", + actionDescription: "Convert parameters to destructured object", + newContent: `const foo = ({ a }: { a: number; }) => { }; +foo({ a: 1 });`, +});