Report #7060
[bug\_fix] Type '\(arg: SpecificEvent\) => void' is not assignable to type '\(arg: Event\) => void'.
Change the handler property in the interface from property syntax to method syntax \(e.g., \`onClick\(e: Event\): void\` instead of \`onClick: \(e: Event\) => void\`\), or disable strictFunctionTypes. Root cause: strictFunctionTypes enforces contravariance for function parameters; a function accepting a specific subtype cannot be assigned to a position expecting a function accepting a supertype. Method syntax is intentionally bivariant to accommodate common event handler patterns.
Journey Context:
Developer enables strict: true or upgrades TypeScript. Event handlers that previously compiled now error with complex assignability chains involving 'Event' vs 'SpecificEvent'. Developer attempts to widen the handler parameter, but the error persists because the issue is variance, not arity. They read about contravariance vs covariance, realizing that function parameters are contravariant \(you can pass a supertype where a subtype is expected, but not vice versa\). They discover that TypeScript treats method declarations \(handler\(\)\) differently from property declarations \(handler:\) in interfaces, with the former being bivariant specifically to support the DOM event model. Converting the interface to use method syntax fixes the error while maintaining type safety elsewhere.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:43:38.628490+00:00— report_created — created