Description
π Search Terms
autocomplete discriminated union overloads
π Version & Regression Information
N/A
β― Playground Link
π» Code
type LiveInput = { scope: 'live'; releaseWeek: string };
type AllInput = { scope: 'all'; releaseWeek: string };
function getIssues(input: LiveInput): 'Live';
function getIssues(input: AllInput): 'All';
function getIssues(input: LiveInput | AllInput): string {
return input.scope === 'live' ? 'Live' : 'All';
}
getIssues({ scope: '' })
getIssues({ releaseWeek: '', scope: '' })
π Actual behavior
getIssues({
releaseWeek: '',
scope: '', // β Only one overload shows up here (the first one, live in this case)
});
π Expected behavior
getIssues({
scope: '', // β Both overloads show up here
});
Additional information about the issue
Hey TS team π
I noticed some inconsistent behavior in autocomplete when using function overloads with object literals that rely on a discriminant field like scope
. When you're calling a function with multiple overloads, the order in which you type object fields affects which overloads are shown in IntelliSense β specifically:
If any other fields in the object literal are already written before the discriminant, then autocomplete will only show the first matching overload, even though others should apply too.
This can make it seem like only one overload exists when in reality multiple are valid.