Skip to content

Commit

Permalink
Add signature restriction for __spreadArray
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Jun 10, 2021
1 parent b5a1133 commit 40fa251
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40726,6 +40726,11 @@ namespace ts {
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);
}
}
else if (helper & ExternalEmitHelpers.SpreadArray) {
if (!some(getSignaturesOfSymbol(symbol), signature => getParameterCount(signature) > 2)) {
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);
}
}
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions tests/baselines/reference/arraySpreadImportHelpers.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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'.


==== tests/cases/conformance/es6/spread/main.ts (1 errors) ====
export {};
const k = [1, , 2];
const o = [3, ...k, 4];
~~~~
!!! 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'.

==== tests/cases/conformance/es6/spread/tslib.d.ts (0 errors) ====
// this is a pre-TS4.4 versions of emit helper, which always forced array packing
declare module "tslib" {
function __spreadArray(to: any[], from: any[]): any[];
}

16 changes: 16 additions & 0 deletions tests/cases/conformance/es6/spread/arraySpreadImportHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @target: es5
// @importHelpers: true
// @isolatedModules: true
// @noTypesAndSymbols: true
// @noEmit: true
// @filename: main.ts

export {};
const k = [1, , 2];
const o = [3, ...k, 4];

// @filename: tslib.d.ts
// this is a pre-TS4.4 versions of emit helper, which always forced array packing
declare module "tslib" {
function __spreadArray(to: any[], from: any[]): any[];
}

0 comments on commit 40fa251

Please sign in to comment.