Skip to content
webtype.orgwebtype.orgtsconfig

    ↑↓ move · ⏎ open · esc close

    tsconfig

    strictBindCallApply

    call, apply and bind get real signatures

    Without it, these three accept any arguments at all, because their declared types say `any[]`.

    Since
    TypeScript 3.2
    strict
    In strict
    In your tsconfig
    "strictBindCallApply": true
    Compiled with
    "strict": true

    The same snippet both times. Only the option changed.

    With it off

    "strictBindCallApply": false
    function greet(name: string) {
      return name
    }
    
    export const wrong = greet.call(undefined, 42)

    Compiles clean

    With it on

    "strictBindCallApply": true
    function greet(name: string) {
      return name
    }
    
    export const wrong = greet.call(undefined, 42)

    Emits TS2345

    Why the compiler bothers

    The check was impossible to express until variadic tuple types existed, so the standard library declared these methods with `any[]` and every call through them was unchecked. That is a strange hole to leave in an otherwise strict build: the same mistake written as a direct call is caught, and written through `.call` is not. The flag swaps in the generic signatures that do the arithmetic on the parameter tuple.

    Takeaway

    If variadic tuples are how it is checked, a compiler too old for them cannot check it.

    Where to go next

    22 options