-
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.
Proper treatment of splicing tuples in array literals
Fixes #32465. After this was done, I continued to extend the implementation to handle TupleLike types but it'ss broken since JS doesn't allow splicing TupleLike values into array literals so pulled that out, and instead keeping it for reference below. (It Includes tests, which are broken too.) modified src/compiler/checker.ts @@ -22268,6 +22268,21 @@ namespace ts { else hasNonEndingSpreadElement = true; } } + else if (spreadType && isTupleLikeType(spreadType)) { + let i = 0, tupleEltType: Type | undefined; + while (tupleEltType = getTypeOfPropertyOfType(spreadType, "" + i as __String)) { + elementTypes.push(tupleEltType); + i++; + } + const stringIndexInfo = getIndexInfoOfType(spreadType, IndexKind.String); + const numberIndexInfo = getIndexInfoOfType(spreadType, IndexKind.Number); + if (stringIndexInfo || numberIndexInfo) { + if (stringIndexInfo) elementTypes.push(stringIndexInfo.type); + if (numberIndexInfo) elementTypes.push(numberIndexInfo.type); + if (i === elementCount - 1) hasEndingSpreadElement = true; + else hasNonEndingSpreadElement = true; + } + } else { if (inDestructuringPattern && spreadType) { // Given the following situation: new file tests/cases/compiler/spliceTupleLikesWIntegers.ts @@ -0,0 +1,23 @@ +declare const sb: { [0]: string, [1]: boolean }; + +let k1: [number, string, boolean]; +k1 = [1, ...sb]; + +let k2: [number, string, boolean, number]; +k2 = [1, ...sb, 1]; + +// declare const sb_: [string, ...boolean[]]; + +// let k3: [number, string, ...boolean[]]; +// k3 = [1, ...sb_]; + +// declare const sbb_: [string, boolean, ...boolean[]]; + +// let k4: [number, string, ...boolean[]]; +// k4 = [1, ...sbb_]; + +// let k5: [number, string, boolean, ...boolean[]]; +// k5 = [1, ...sbb_]; + +// let k6: [number, string, boolean, boolean, ...boolean[]]; +// k6 = [1, ...sbb_]; new file tests/cases/compiler/spliceTupleLikesWStrings.ts @@ -0,0 +1,23 @@ +declare const sb: { 0: string, 1: boolean }; + +let k1: [number, string, boolean]; +k1 = [1, ...sb]; + +let k2: [number, string, boolean, number]; +k2 = [1, ...sb, 1]; + +declare const sb_: { 0: string, [s: string]: (boolean|string) }; + +let k3: [number, string, ...(boolean|string)[]]; +k3 = [1, ...sb_]; + +declare const sbb_: { 0: string, 1: boolean, [s: string]: (boolean|string) }; + +let k4: [number, string, boolean, ...(boolean|string)[]]; +k4 = [1, ...sbb_]; + +// let k5: [number, string, boolean, ...(boolean|string)[]]; +// k5 = [1, ...sbb_]; + +// let k6: [number, string, boolean, boolean, ...(boolean|string)[]]; +// k6 = [1, ...sbb_];
- Loading branch information
1 parent
26184f0
commit db1c440
Showing
21 changed files
with
307 additions
and
88 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
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
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
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
15 changes: 0 additions & 15 deletions
15
tests/baselines/reference/restElementWithAssignmentPattern1.errors.txt
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.