Skip to content

Commit 40fa251

Browse files
committed
Add signature restriction for __spreadArray
1 parent b5a1133 commit 40fa251

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40726,6 +40726,11 @@ namespace ts {
4072640726
error(location, Diagnostics.This_syntax_requires_an_imported_helper_named_1_with_2_parameters_which_is_not_compatible_with_the_one_in_0_Consider_upgrading_your_version_of_0, externalHelpersModuleNameText, name, 5);
4072740727
}
4072840728
}
40729+
else if (helper & ExternalEmitHelpers.SpreadArray) {
40730+
if (!some(getSignaturesOfSymbol(symbol), signature => getParameterCount(signature) > 2)) {
40731+
error(location, Diagnostics.This_syntax_requires_an_imported_helper_named_1_with_2_parameters_which_is_not_compatible_with_the_one_in_0_Consider_upgrading_your_version_of_0, externalHelpersModuleNameText, name, 3);
40732+
}
40733+
}
4072940734
}
4073040735
}
4073140736
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
tests/cases/conformance/es6/spread/main.ts(3,15): error TS2807: This syntax requires an imported helper named '__spreadArray' with 3 parameters, which is not compatible with the one in 'tslib'. Consider upgrading your version of 'tslib'.
2+
3+
4+
==== tests/cases/conformance/es6/spread/main.ts (1 errors) ====
5+
export {};
6+
const k = [1, , 2];
7+
const o = [3, ...k, 4];
8+
~~~~
9+
!!! error TS2807: This syntax requires an imported helper named '__spreadArray' with 3 parameters, which is not compatible with the one in 'tslib'. Consider upgrading your version of 'tslib'.
10+
11+
==== tests/cases/conformance/es6/spread/tslib.d.ts (0 errors) ====
12+
// this is a pre-TS4.4 versions of emit helper, which always forced array packing
13+
declare module "tslib" {
14+
function __spreadArray(to: any[], from: any[]): any[];
15+
}
16+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @target: es5
2+
// @importHelpers: true
3+
// @isolatedModules: true
4+
// @noTypesAndSymbols: true
5+
// @noEmit: true
6+
// @filename: main.ts
7+
8+
export {};
9+
const k = [1, , 2];
10+
const o = [3, ...k, 4];
11+
12+
// @filename: tslib.d.ts
13+
// this is a pre-TS4.4 versions of emit helper, which always forced array packing
14+
declare module "tslib" {
15+
function __spreadArray(to: any[], from: any[]): any[];
16+
}

0 commit comments

Comments
 (0)