Revision e71614a185eaafa080664902f1bb7fa2802dbd01 authored by Eli Barzilay on 13 February 2020, 21:09:20 UTC, committed by Eli Barzilay on 27 February 2020, 21:43:29 UTC
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_];
1 parent 6c5c48c
History
File Mode Size
.github
.vscode
bin
doc
lib
loc
scripts
src
tests
.dockerignore -rw-r--r-- 1.0 KB
.editorconfig -rw-r--r-- 188 bytes
.eslintignore -rw-r--r-- 59 bytes
.eslintrc.json -rw-r--r-- 4.2 KB
.gitattributes -rw-r--r-- 42 bytes
.gitignore -rw-r--r-- 2.8 KB
.gitmodules -rw-r--r-- 0 bytes
.mailmap -rw-r--r-- 18.7 KB
.npmignore -rw-r--r-- 411 bytes
.npmrc -rw-r--r-- 18 bytes
.travis.yml -rw-r--r-- 296 bytes
.yarnrc -rw-r--r-- 27 bytes
AUTHORS.md -rw-r--r-- 8.3 KB
CODE_OF_CONDUCT.md -rw-r--r-- 333 bytes
CONTRIBUTING.md -rw-r--r-- 10.5 KB
CopyrightNotice.txt -rw-r--r-- 812 bytes
Dockerfile -rw-r--r-- 257 bytes
Gulpfile.js -rw-r--r-- 32.5 KB
LICENSE.txt -rw-r--r-- 9.0 KB
README.md -rw-r--r-- 5.5 KB
ThirdPartyNoticeText.txt -rw-r--r-- 36.9 KB
package.json -rw-r--r-- 4.2 KB

README.md

back to top