functionCurryingRedundancy
Reports using
.apply()or.call()or when the context (thisvalue) provides no benefit.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
Using .apply() .call() or with null or undefined as the context (first argument) provides no benefit over calling the function directly.
Doing so adds unnecessary complexity and reduces code readability.
Examples
Section titled “Examples”function function add(a: number, b: number): number
add(a: number
a: number, b: number
b: number) { return a: number
a + b: number
b;}const const result: number
result = function add(a: number, b: number): number
add.CallableFunction.call<undefined, [number, number], number>(this: (this: undefined, args_0: number, args_1: number) => number, thisArg: undefined, args_0: number, args_1: number): number
Calls the function with the specified object as the this value and the specified rest arguments as the arguments.
call(var undefined
undefined, 1, 2);function function multiply(x: number, y: number): number
multiply(x: number
x: number, y: number
y: number) { return x: number
x * y: number
y;}const const value: number
value = function multiply(x: number, y: number): number
multiply.CallableFunction.call<null, [number, number], number>(this: (this: null, args_0: number, args_1: number) => number, thisArg: null, args_0: number, args_1: number): number
Calls the function with the specified object as the this value and the specified rest arguments as the arguments.
call(null, 5, 3);const const callback: (message: string) => string
callback = (message: string
message: string) => message: string
message.String.toUpperCase(): string
Converts all the alphabetic characters in a string to uppercase.
toUpperCase();const callback: (message: string) => string
callback.CallableFunction.apply<undefined, [message: string], string>(this: (this: undefined, message: string) => string, thisArg: undefined, args: [message: string]): string (+1 overload)
Calls the function with the specified object as the this value and the elements of specified array as the arguments.
apply(var undefined
undefined, ["hello"]);const const compute: (a: number, b: number) => number
compute = (a: number
a: number, b: number
b: number) => a: number
a + b: number
b;const compute: (a: number, b: number) => number
compute.CallableFunction.apply<null, [a: number, b: number], number>(this: (this: null, a: number, b: number) => number, thisArg: null, args: [a: number, b: number]): number (+1 overload)
Calls the function with the specified object as the this value and the elements of specified array as the arguments.
apply(null, [10, 20]);function function add(a: number, b: number): number
add(a: number
a: number, b: number
b: number) { return a: number
a + b: number
b;}const const result: number
result = function add(a: number, b: number): number
add(1, 2);const const callback: (message: string) => string
callback = (message: string
message: string) => message: string
message.String.toUpperCase(): string
Converts all the alphabetic characters in a string to uppercase.
toUpperCase();const callback: (message: string) => string
callback("hello");// Using .call() with a meaningful contextconst const obj: { value: number;}
obj = { value: number
value: 10 };function function getValue(): any
getValue() { return this.any
value;}const const contextResult: any
contextResult = function getValue(): any
getValue.CallableFunction.call<{ value: number;}, [], any>(this: (this: { value: number;}) => any, thisArg: { value: number;}): any
Calls the function with the specified object as the this value and the specified rest arguments as the arguments.
call(const obj: { value: number;}
obj);// Using .apply() to pass an array of arguments with contextfunction function greet(this: { name: string;}, greeting: string): string
greet(this: { name: string;}
this: { name: string
name: string }, greeting: string
greeting: string) { return `${greeting: string
greeting}, ${this.name: string
name}!`;}const const person: { name: string;}
person = { name: string
name: "Alice" };function greet(this: { name: string;}, greeting: string): string
greet.CallableFunction.apply<{ name: string;}, [greeting: string], string>(this: (this: { name: string;}, greeting: string) => string, thisArg: { name: string;}, args: [greeting: string]): string (+1 overload)
Calls the function with the specified object as the this value and the elements of specified array as the arguments.
apply(const person: { name: string;}
person, ["Hello"]);Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you have a specific coding pattern that requires explicit use of .apply() .call() or for consistency across a large codebase, even when the context is null or undefined, you might choose to disable this rule.
However, in most cases, direct function calls improve code clarity and maintainability.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
no-useless-call - Oxlint:
eslint/no-useless-call