Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท tsconfig: Type Checking Options

TypeScript strictBindCallApply option

Reference for strictBindCallApply in TypeScript: how bind, call and apply are checked against the real function signature, with errors and fixes.

Every JavaScript function has the methods call, apply and bind. In older TypeScript they were typed loosely, accepting any arguments and returning any. With strictBindCallApply they are checked against the function's real signature: the argument types are verified, the right number of arguments is required, and bind returns a correctly typed function with the bound arguments removed.

The flag is part of strict. It works through the built-in CallableFunction and NewableFunction interfaces, which declare generic versions of these methods.

TypeScript
function add(a: number, b: number): number {
  return a + b;
}
add.call(null, 1, 2);        // fine, returns number
// add.call(null, "1", 2);   // error under the flag

Try it

TypeScript Wrong argument types are caught

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

TypeScript Typed bind and this

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Syntax

JSON
{ "compilerOptions": { "strictBindCallApply": true } }
TypeScript
fn.call(thisArg, ...args)      // args checked against fn's parameters
fn.apply(thisArg, argsTuple)   // argsTuple must match the parameter tuple
fn.bind(thisArg, ...first)     // returns a function taking the remaining parameters
Method Returns What is checked
call The function's return type thisArg against the declared this, each argument against its parameter.
apply The function's return type A tuple of arguments matches the parameter list.
bind A function of the remaining parameters thisArg and the leading arguments; up to a fixed number of bound arguments are typed precisely (beyond that, rest typing applies).

Edge cases: overloaded functions are resolved using only the last overload for call, apply and bind, which can give surprising errors. Generic functions lose their generics when bound (the type parameters become their constraints). Optional parameters stay optional.

Usage notes

  • Without the flag these methods take ...args: any[] and return any, so wrong calls pass silently.
  • Arrow functions ignore thisArg; bind on an arrow function still type-checks the arguments but cannot change this.
  • Prefer arrow functions or closures to bind in modern code; they infer more naturally and need no this handling.
  • apply with a spread array of unknown length (number[]) fails against fixed parameters. Use a tuple type or spread directly: fn(...args).
  • Declare this in function parameters (this: T) so call and bind can verify the receiver; see this in functions.
  • Methods taken from classes lose this when passed around; bind(instance) or an arrow-function field is the typical fix.
  • Overload surprise: if bind picks the wrong overload, wrap the call in a small typed function.