Untyped function calls may not accept type arguments.ts(2347)

Umar Farooque Khan
2 min readJul 3, 2023

--

The error message you provided, “Untyped function calls may not accept type arguments.ts(2347)” is a TypeScript error that occurs when you attempt to pass type arguments to a function that has not been explicitly typed or annotated to accept them.

In TypeScript, you can specify the types of function parameters and the return type using type annotations. This allows the compiler to perform type checking and ensure that the function is called correctly. However, if you call a function without explicitly providing type arguments and the function itself does not have type annotations to accept them, TypeScript will raise the error you mentioned.

Here’s an example to illustrate the error:

function add(a: number, b: number): number {
return a + b;
}

const result = add<number>(2, 3); // Error: Untyped function calls may not accept type arguments.ts(2347)

In this example, the add function is defined with type annotations for the parameters and the return type. However, when calling the function, <number> is provided as a type argument. Since the add function doesn't have type annotations to accept type arguments, TypeScript raises the error.

To resolve this issue, you have a few options:

  1. Remove the type arguments: If the function doesn’t need type arguments, simply call it without providing them.
const result = add(2, 3); // No error
  1. Add type annotations to accept type arguments: If you intend to pass type arguments to the function, make sure to add type annotations to the function declaration.
function add<T>(a: T, b: T): T {
return a + b;
}

const result = add<number>(2, 3); // No error

By adding <T> to the function signature, we can now pass type arguments to the add function without TypeScript raising an error.

It’s important to note that the specific solution depends on the context in which the error occurs and the intention behind the function call. The above examples provide general approaches to address the “Untyped function calls may not accept type arguments.ts(2347)” error.

--

--

Umar Farooque Khan
Umar Farooque Khan

Written by Umar Farooque Khan

Experienced software developer with a passion for clean code and problem-solving. Full-stack expertise in web development. Lifelong learner and team player.

No responses yet