You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unsafe assignment allowed from a function union to a function type with rest parameters #62447
No type error is reported on the assignment const g: G = f.
This allows a subsequent call g() which is type-safe according to G's signature. However, because the assigned implementation f requires an argument, this valid call leads to a runtime TypeError.
The type system is allowing an assignment that is demonstrably unsafe at runtime.
🙂 Expected behavior
A type error should be reported on the line const g: G = f.
The assignment should be disallowed because not all constituents of the union type F are safely assignable to the type G.
Specifically, the (text: string) => number member of F cannot be safely called with zero arguments, but the target type G explicitly allows being called with zero arguments. Therefore, the assignment creates a situation where a runtime error is inevitable if that code path is taken, which defeats the purpose of static type checking.
Activity
jcalz commentedon Sep 14, 2025
This has little to do with unions; you can expose the same unsoundness with
As such this is a known and intentionally allowed unsoundness, and this issue is a duplicate of, say, #58552