T
T
tostershmoster2021-07-31 16:03:57
typescript
tostershmoster, 2021-07-31 16:03:57

Why does eslint throw an error 'arg' is defined but never used?


RangeSlider(arg? : any): JQuery;

I get an error on the line

'arg' is defined but never used

Why? The parameter 'userOptions' is passed in the line All code
$.fn.RangeSlider = function(userOptions): JQuery

import { Model } from '../Model/Model';
import View from '../View/View';
import Presenter from '../Presenter/Presenter';

declare global {
  interface JQuery {
    RangeSlider(arg? : any): JQuery;
  }
}

export interface ISettings {
  min: number;
  max: number;
  isTwoRunners: boolean;
  isScaleVisible: boolean;
  isVertical: boolean;
  isTooltipsVisible: boolean;
  valueFrom: number;
  valueTo: number;
  step: number;
}

(function($) {
  const defaultSettings: ISettings = {
    min: 0,
    max: 100,
    isTwoRunners: true,
    isScaleVisible: false,
    isTooltipsVisible: true,
    isVertical: false,
    valueFrom: 30,
    valueTo: 70,
    step: 1,
  };

  $.fn.RangeSlider = function(userOptions): JQuery {
    const mergedSettings = $.extend({}, defaultSettings, userOptions);
    const elementId: string | null = this[0] ? `#${this[0].id}` : null;

    const model: Model = new Model(mergedSettings);
    const view: View = new View(elementId);
    const presenter: Presenter = new Presenter(model, view);

    return this;
  };
}(jQuery));


$('#range-slider').RangeSlider({
  min: 100,
  max: 150,
  valueFrom: 140,
  valueTo: 149,
  isScaleVisible: true,
  isVertical: false,
  step: 10,
});


Moreover, if you remove "arg? : any". This is how it
RangeSlider(): JQuery;

throws an error
Type '(userOptions: any) => JQuery' is not assignable to type '() => JQuery'.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2021-07-31
@tostershmoster

Wangyu you have the original no-unused-vars rule from eslint itself, which does not understand type descriptions from TypeScript, you should use the rule from the @typescript-eslint/no-unused-vars plugin instead

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question