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
.travis.yml
language: node_js
node_js:
- 'node'
- '10'
- '8'
env:
- workerCount=3 timeout=600000
matrix:
fast_finish: true
branches:
only:
- master
- /^release-.*/
install:
- npm uninstall typescript --no-save
- npm install
cache:
directories:
- node_modules
git:
depth: 1
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...