Optional discriminated union's callback parameter type is not inferred #46847
Copy link
Copy link
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: check: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolutionRelated to type inference performed during signature resolution or `infer` type resolution
Milestone
Description
Bug Report
Optional discriminated union's callback parameter type is not inferred
🔎 Search Terms
🕗 Version & Regression Information
⏯ Playground Link
💻 Code
type A = {
type?: 'A',
a: (c: { d: number }) => void;
}
type B = {
type: 'B',
a: (c: { d: number, c: string }) => void;
}
type ABC = A | B ;
var a: ABC[] | Record<string, ABC[]> = [
{
a: (params) => {
}
}
]🙁 Actual behavior
Parameters of method 'a' can not be inferred correctly.
🙂 Expected behavior
Parameters of method 'a 'can be inferred correctly: {d: number}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: check: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolutionRelated to type inference performed during signature resolution or `infer` type resolution
Activity
RyanCavanaugh commentedon Nov 18, 2021
Behavior dates back to at least 3.3.3. It looks like our discriminant detection is getting a little confused by the
Recordpart of the union.wzono commentedon Dec 10, 2021
Ryan Cavanaugh (@RyanCavanaugh) Any progress?
RyanCavanaugh commentedon Dec 13, 2021
@wingsico no
Eldemarkki commentedon Aug 4, 2023
Any updates?
I'm not sure if this Playground link is the same problem as this, but if true, then still exists in 5.1.6: https://www.typescriptlang.org/play?ts=5.1.6#code/C4TwDgpgBAEghgOwCYBsICcAKd1wLYTAYDOUAvFAN4BQUdUAjgK4YgBqcKAlknMAPboAXFAAUASnIA+KACN+-NIgDctegAtEqDCNHNWIylB4jiwdFwQBzKAF9JZGQDd+PVbagAfKmrr707Jw8fIIA-CJMyBAAZpYQSKr0UJrIaMJi-iARUbEI8Q7OrgnUtqrUAMb8CGZQYDj4pBQ0SZkc3LwC6RLSUOYsADS+yVppupkFPklJldWKEAB0KPxWeiwB4kO2tB7EfFzEsRCk8KkY2LgEROjEqkA