Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk4 min

TypeScript 6.0 Can Break Callback Assignments: What Strict Function Types Actually Check

TypeScript 6.0 can expose callback assignment errors because strict mode now defaults to true. Learn what contravariance checks, how to inspect your configuration, and which fixes preserve type safety.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

TypeScript 6.0 can expose callback assignment errors in projects that relied on the old default of strict: false. It did not introduce strict function checking: strictFunctionTypes has existed since TypeScript 2.6. The error is about safety: a callback that handles only a narrow input cannot be placed in a slot whose callers are allowed to pass a wider range of values.

Why does TypeScript say my callback type is not assignable?

Under strictFunctionTypes, TypeScript checks function parameter types contravariantly. In practical terms, the supplied callback must be able to accept every value the callback slot promises it might receive.

As an Amazon Associate I earn from qualifying purchases.

Suppose Animal is the wider type and Dog is narrower. A function that accepts any Animal can safely be used where a function accepting only Dog is expected: it can handle a dog. The reverse is not safe. A function that accepts only Dog cannot safely fill a slot that may pass any Animal, because a caller could pass a cat.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
type Animal = { name: string };
type Dog = Animal & { bark(): void };

declare function registerAnimalHandler(handler: (animal: Animal) => void): void;

const handleDog = (dog: Dog) => dog.bark();
registerAnimalHandler(handleDog); // Error: a caller could pass a non-Dog

const handleAnimal = (animal: Animal) => console.log(animal.name);
declare function registerDogHandler(handler: (dog: Dog) => void): void;
registerDogHandler(handleAnimal); // Safe: it can handle any Dog

The assignment direction can feel counterintuitive if you focus on the names of the types. Think instead about the caller: what values is the slot allowed to pass, and can the supplied function handle all of them?

What changes in TypeScript 6.0?

TypeScript 6.0 changes the default for strict to true. A project that omitted strict and depended on the earlier non-strict default may therefore receive new type errors after upgrading. The change is in the default configuration, not the origin of contravariant callback checking. The TypeScript 2.6 release introduced strictFunctionTypes as part of the strict family of checks.

The TSConfig reference describes strictFunctionTypes as true when strict is true and false otherwise. It can also be set directly. Check the TypeScript 6.0 release notes and the strictFunctionTypes option reference for the documented defaults and migration guidance.

Rank #2
TypeScript Programming Language - Software Engineer & Coder T-Shirt
  • TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
  • TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

How do I check which setting is causing the error?

  1. Confirm the compiler version. Check the TypeScript version used by the build or editor; different invocations can use different installations.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  2. Inspect the configuration and invocation. Look for strict and strictFunctionTypes in the applicable tsconfig.json, and check whether the build command selects a different config or passes compiler options on the command line.

  3. Check the effective setting. The TypeScript configuration reference gives the strict-dependent default: strictFunctionTypes is enabled when strict is enabled, and disabled otherwise. An explicit option can determine the setting directly.

  4. Read the callback contract. Identify the complete set of inputs the declared callback slot may receive. Compare that set with what the implementation can actually handle.

The official TypeScript 6.0 release notes advise projects that relied on the previous default to set "strict": false explicitly. That preserves the prior broad strict-mode choice; it does not repair an unsafe callback contract.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What is the safe fix for a strictFunctionTypes error?

Broaden the callback parameter when the implementation can handle it

If the callback is genuinely able to process every value permitted by its slot, declare that broader input. For example, use (animal: Animal) => void rather than (dog: Dog) => void when the function does not require dog-specific behavior. This fixes the mismatch at the function boundary and preserves the safety check.

Correct the API contract when callers cannot supply the wider type

If the API will only ever invoke the callback with a Dog, its declaration should express that narrower contract. Make this change only when it accurately describes the API’s behavior; otherwise callers may rely on a promise the implementation does not keep.

Keep the old project-wide setting only as a deliberate migration choice

Setting "strict": false can preserve the previous default for a project that is not ready to adopt strict checks. Alternatively, configure strictFunctionTypes explicitly if that is the specific check being managed. Treat either choice as configuration scope, not as proof that an individual callback assignment is safe.

Avoid using a cast as the routine repair

A cast can silence the diagnostic, but it does not make a callback that accepts only dogs safe to call with cats. Use one only when you can independently guarantee the stronger condition the type checker cannot establish; otherwise fix the callback or the API declaration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why do methods sometimes behave differently?

TypeScript’s strict contravariant check applies to function types, with an intentional exception for parameters originating in method or constructor declarations. As a result, a method signature and a function-valued property with otherwise similar types can have different assignability behavior.

The exception is a compatibility and type-system design choice. TypeScript 2.6’s release notes explain that it helps generic classes and interfaces such as Array<T> remain mostly covariant. It is not a claim that methods are universally safer at runtime, so changing a function property into a method solely to get past an error can hide an unsafe contract rather than fix it. See the TypeScript 2.6 release notes and the Type Compatibility handbook for the rule and its rationale.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.