Closed
Description
🔎 Search Terms
typealias inference, union type inference, intersection type inference, inconsistent inference
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about type inference
⏯ Playground Link
💻 Code
export interface BreakerInterface {
}
export function brokenUsage<S, E>(result: Unionizer<S, E>) {
}
export type Unionizer<S, E> = (S | E) & BreakerInterface
export type UnionizerUsage = Unionizer<void, string>
function failedInference() {
const x: UnionizerUsage = getInstance()
// Check fails for no reason
brokenUsage(x)
}
function successInference() {
const x: Unionizer<void, string> = getInstance()
// Same types as before but check succeeds
brokenUsage(x)
}
function getInstance(): UnionizerUsage {}
🙁 Actual behavior
Code fails to compile due to "Type 'void & BreakerInterface' is not assignable to type 'string'" which is actually due to the brokenUsage
call inferring x
as Unionizer<string, string>
instead of Unionizer<void, string>
.
🙂 Expected behavior
UnionizerUsage
is expanded to Unionizer<void, string>
and code compiles
Additional information about the issue
No response