Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TypeScript · Const

strictFunctionTypes

strictFunctionTypes makes function parameter comparisons contravariant instead of bivariant, catching unsafe callback assignments. It is enabled by strict mode but does not apply to methods or constructors.

Since
2.6

How it works

The strictFunctionTypes compiler option makes function-parameter comparison contravariant instead of bivariant. It prevents assigning a callback that accepts only a narrower type to a callback type that may pass a broader type; method and constructor declarations remain exempt.

Syntax

"strictFunctionTypes": true

Parameters

NameTypeDescription
strictFunctionTypesbooleanBoolean compiler setting that controls strict checking of function parameter positions.

Key points

  • The feature is a compiler option introduced in TypeScript 2.6.
  • Enabling the umbrella strict option turns this check on unless it is explicitly overridden.
  • Function parameters must be checked contravariantly rather than accepting either variance direction.
  • A function assignment accepted by default checking can become a compile-time error under this option.
  • Some incompatible function assignments remain errors regardless of whether strictFunctionTypes is enabled.

Common mistakes

  • The option does not apply the stricter parameter check to methods or constructors, so an unsafe method assignment can still be accepted.
  • The check can be disabled explicitly, even when strict checking is otherwise being used.

Example: Rejecting an unsafe function assignment

function handleString(value: string) {
  console.log(value.toLowerCase());
}

type StringOrNumberHandler = (value: string | number) => void;

// Error: a number could reach handleString.
const handler: StringOrNumberHandler = handleString;

With strictFunctionTypes enabled, TypeScript rejects this unsafe assignment because the declared handler may receive a number.

When to use it

Prevent unsafe callback assignment

A callback type accepts a union, but an implementation accepts only one member of that union.

Adopt strict-mode checking

A large project wants stricter function compatibility checks as part of its standard compiler policy.

Preserve method compatibility

A compatibility-sensitive generic class or interface relies on method declarations rather than function-valued properties.

Interview questions

QWhat does strictFunctionTypes change?

It changes function-parameter checking from bivariance to contravariance. A callback accepting only string cannot implement a callback type that might invoke it with string or number, because that assignment is unsafe.

Follow-up: Why are methods excluded? The documented reason is to preserve compatibility for generic classes and interfaces such as Array<T>, whose existing relationships could otherwise become unsafe or break.

QWhy is the assignment from a string-only callback unsafe?

With the option enabled, assigning (x: string) => void to (x: string | number) => void is rejected because the target could call the function with a number. This catches a call that would otherwise fail at runtime.

Follow-up: What happens when the option is disabled? The assignment is permitted because default checking treats the situation as possibly sound, even though it is not provably safe.

QHow is strictFunctionTypes configured?

The option belongs to TypeScript's strict family and is enabled by strict mode by default. It can also be controlled directly in tsconfig.json or through the compiler command line.

Follow-up: How can a project selectively disable it? Set strictFunctionTypes to false, or pass --strictFunctionTypes false on the command line.

  • strict
  • strictNullChecks
  • Type Compatibility
  • Function Parameter Bivariance
  • Comparer<T>

Source: Documentation - TypeScript 2.6. Checked 2026-10-15.