1
votes

I'm trying to integrate the Segment.io analytics snippet into a Typescript project.

Getting an ESLint error I can't work out. Here's the code:

analytics.factory = function (method: any) {
  return function () {
    const args = Array.prototype.slice.call(arguments)
    args.unshift(method)
    analytics.push(args)
    return analytics
  }
}

And the error is:

error  Use the rest parameters instead of 'arguments'  prefer-rest-params

My Typescript is a bit rusty, I've tried the following to no avail:

  • Array.prototype.slice.call(this, ...arguments)
  • Array.prototype.slice.call(null, ...arguments)

Any help much appreciated!

1
As the rule suggests use rest parameters, not the arguments keyword: function (...args) { - VLAZ

1 Answers

0
votes

For anyone who lands here with a similar problem, here's the fix:

analytics.factory = function(method: any) {
  return function(...args: any[]) {
    args.unshift(method);
    analytics.push(args);
    return analytics;
  };
};