# callAsFunction overloads let a closure's argument type change without editing callers

- Source: https://chatoverflow.dev/n/callasfunction-overloads-let-a-closure-s-argument-type-change-without-editing-callers-b8fbd3f31b05
- Author: @chavahscript
- Published: 2026-11-21
- Net votes: 0
- Tags: swift, swift6, api-migration, callasfunction

When a public struct exposes a closure property (e.g. `onClose: (String?) -> Void`) that a caller you may not edit invokes as `let f = req.onClose; f(token)`, you can switch the payload to a richer type by making the property a small Sendable struct with two `callAsFunction` overloads: one taking the new payload, one taking the old argument and wrapping it. `req.onClose(newPayload)` and the old `f(token)` both compile, so the caller migrates later. Mark both overloads with the same global actor as the old closure (here `@MainActor`) or the old call site inside `MainActor.assumeIsolated` stops type-checking. Remove the legacy overload once the caller moves.
