-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix convert to named parameters rest parameter tuple (#30286)
* check if rest parameter is of tuple type in isOptionalParameter * expose isArrayType and isTupleType in checker * don't offer refactor if rest parameter type is neither array nor tuple type * add tests for rest parameters * fix tests for renamed refactor * remove unnecessary conditional operator
- Loading branch information
Showing
5 changed files
with
131 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
tests/cases/fourslash/refactorConvertParamsToDestructuredObject_badRestParam.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @Filename: a.ts | ||
////function /*a*/gen<T extends any[]>/*b*/(a: boolean, ...b: T): T { | ||
//// return b; | ||
////} | ||
////gen(false); | ||
////gen(false, 1); | ||
////gen(true, 1, "two"); | ||
|
||
// @Filename: b.ts | ||
////function /*c*/un/*d*/(a: boolean, ...b: number[] | [string, string]) { | ||
//// return b; | ||
////} | ||
|
||
goTo.select("a", "b"); | ||
verify.not.refactorAvailable("Convert to named parameters"); | ||
|
||
goTo.select("c", "d"); | ||
verify.not.refactorAvailable("Convert to named parameters"); |
57 changes: 57 additions & 0 deletions
57
tests/cases/fourslash/refactorConvertParamsToDestructuredObject_tupleRestParam.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @Filename: a.ts | ||
////function /*a*/fn1/*b*/(a: number, b: number, ...args: [number, number]) { } | ||
////fn1(1, 2, 3, 4); | ||
|
||
// @Filename: b.ts | ||
////function /*c*/fn2/*d*/(a: number, b: number, ...args: [number, number, ...string[]]) { } | ||
////fn2(1, 2, 3, 4); | ||
////fn2(1, 2, 3, 4, "a"); | ||
|
||
// @Filename: c.ts | ||
////function /*e*/fn3/*f*/(b: boolean, c: []) { } | ||
////fn3(true, []); | ||
|
||
// @Filename: d.ts | ||
////function /*g*/fn4/*h*/(a: number, ...args: [...string[]] ) { } | ||
////fn4(2); | ||
////fn4(1, "two", "three"); | ||
|
||
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: `function fn1({ a, b, args }: { a: number; b: number; args: [number, number]; }) { } | ||
fn1({ a: 1, b: 2, args: [3, 4] });` | ||
}); | ||
|
||
goTo.select("c", "d"); | ||
edit.applyRefactor({ | ||
refactorName: "Convert parameters to destructured object", | ||
actionName: "Convert parameters to destructured object", | ||
actionDescription: "Convert parameters to destructured object", | ||
newContent: `function fn2({ a, b, args }: { a: number; b: number; args: [number, number, ...string[]]; }) { } | ||
fn2({ a: 1, b: 2, args: [3, 4] }); | ||
fn2({ a: 1, b: 2, args: [3, 4, "a"] });` | ||
}); | ||
|
||
goTo.select("e", "f"); | ||
edit.applyRefactor({ | ||
refactorName: "Convert parameters to destructured object", | ||
actionName: "Convert parameters to destructured object", | ||
actionDescription: "Convert parameters to destructured object", | ||
newContent: `function fn3({ b, c }: { b: boolean; c: []; }) { } | ||
fn3({ b: true, c: [] });` | ||
}); | ||
|
||
goTo.select("g", "h"); | ||
edit.applyRefactor({ | ||
refactorName: "Convert parameters to destructured object", | ||
actionName: "Convert parameters to destructured object", | ||
actionDescription: "Convert parameters to destructured object", | ||
newContent: `function fn4({ a, args = [] }: { a: number; args?: [...string[]]; }) { } | ||
fn4({ a: 2 }); | ||
fn4({ a: 1, args: ["two", "three"] });` | ||
}); |