Urgent.News

One page, thousands of outlets. See who else covered it.

Editions

Tech

TypeScript 6.0 Strict Function Types: Why Contravariance Breaks Your Existing Callbacks

TypeScript 6.0 Strict Function Types: Why Contravariance Breaks Your Existing Callbacks This article was written with the assistance of AI, under human supervision and review. Most TypeScript migration failures stem from a single misunderstood compiler flag: strictFunctionTypes . The pattern that breaks production is deceptively simple—a callback that accepts a base type where the consumer…

TypeScript 6.0 now enforces strictFunctionTypes by default, changing how function parameter types are checked. This affects callbacks that accept base types where consumers expect derived types—a common source of migration failures. The key issue is contravariance, which determines whether a function that accepts a more general type can safely substitute for one that requires a more specific type.

Before TypeScript 6.0, the compiler allowed bivariant checking, where a function expecting a more specific type could be assigned to a variable typed with a more general type, and vice versa. Now, with strictFunctionTypes enabled, TypeScript rejects such assignments, breaking callbacks that relied on this behavior. The problem arises because callbacks registered with array methods expect specific types, but implementations pass derived types.

This mismatch causes compile-time errors, and fixing them requires understanding the underlying variance rules. The solution isn't to weaken types with any casts, which could introduce runtime bugs, but to restructure callbacks using proper variance-aware patterns or switch to method syntax where bivariance is intentional. The migration challenge lies in the hundreds of callbacks that violate contravariance in codebases that never configured strict checking.

The recommended approach is to widen parameter types to unions, use method syntax for intentional bivariance, or introduce generic constraints that preserve assignability without any. Disabling strictFunctionTypes to silence errors creates a type system that diverges from reality, undermining the compiler's safety guarantees.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

The Matte Learns Only Inside the Band

A bad cutout rarely announces itself as a bad cutout. The car lands on a new backdrop, the paint looks clean, then a thin piece is gone. An antenna. A tire lip. The dark seam under a rocker panel.

[Technical Discussion] IPC Message Queue Tuning for WLOADCTL on Linux

WLOADCTL is built as a distributed scheduling platform composed of multiple cooperating processes. Communication between different nodes, such as: Server ↔ Agent Server ↔ Client is handled through…

  • WLOADCTL uses Linux IPC mechanisms like Message Queues for inter-process communication.
  • Default Linux IPC configuration may not support high-volume scheduling workloads in WLOADCTL.

Mongodb Partitioning

At Whoz , we build a SaaS platform that helps professional services companies manage their talent staffing. At the heart of our product lies a concept called a worklog — a record of time spent by a…

More from Tuesday 18 August →