_From @MartinLoeper on August 29, 2018 13:27_
Steps to Reproduce:
I provided a small example of the issue (see screenshot below).
I expect the auto-completion to show "BW" and "BY" only!

Does this issue occur when all extensions are disabled?: Yes
The code:
export class MomentHolidayFactory {
public a(input: Germany, second: GermanState): string;
public a(input: Austria, second: AustrianState): string;
public a(input: Country, second: State): string {
return "test";
}
public holidays() {
this.a("de", ""
}
}
type Country = Germany & Austria;
type Germany = "de" | "De" | "DE" | "germany";
type Austria = "Au" | "au" | "AU" | "austria";
type State = GermanState & AustrianState;
type GermanState = "BW" | "BY";
type AustrianState = "Stmk" | "Vbg";
_Copied from original issue: Microsoft/vscode#57509_
I'm also having an issue with autocomplete on overloaded code:
public select<P extends NonReferenceNonFunctionPropNames<T>>(f: P): string;
public select<P extends NonReferenceNonFunctionPropNames<T>>(f: FunctionField<T>): string;
public select<P extends NonReferenceNonFunctionPropNames<T>>(f: P[]): string[];
public select<P extends NonReferenceNonFunctionPropNames<T>>(f: P | P[] | FunctionField<T>): string | string[] {
let relations = this._traversed.map(r => r.apiName);
if (Array.isArray(f)) {
let fieldArr: string[];
fieldArr = f.map(field => {
return this._obj.FIELDS[field as string].apiName
});
return fieldArr.map(field => {
return [...relations, ...[field]].join('.');
});
} else if (typeof f === 'object') {
let apiName = this._obj.FIELDS[f.field as string].apiName
return renderComplexTypeText([...relations, ...[apiName]].join('.'), f.func, f.alias)
} else {
return [...relations, ...[this._obj.FIELDS[f as string].apiName]].join('.');
}
}
The auto-compete does work on the instances with P instances, but does NOT work when calling the P[] or FunctionField<T> (typechecking does still work, but it's very hard to remember these key names)
What is the expected behavior?
implement a partial signature resolve or fill parameters with correct type?
The signature help is wrong either if the first argument is Austria, the signature help still shows the first overload.
I recently encountered the same problem where I wanted the compiler to restrict arguments based on previous arguments for an overloaded function type. Also, I came up with a solution that works quite well, in my opinion.
First of all, your types need a little fix:
// intersection types do not make much sense, you actually want union types
type Country = Germany | Austria;
type State = GermanState | AustrianState;
With this fix in mind, you can change the function signature in such a manner that you will basically be able to have partial application of your function:
// I removed the class "wrapper" to keep the example small - this should work for methods, as well.
function b(input: Germany): (second: GermanState) => string;
function b(input: Austria): (second: AustrianState) => string;
function b(input: Country): (second: State) => string {
return second => "test";
}
Now, you are forced to apply the function b twice. For the second application, VSCode will suggest more fitting values because the inference of the compiler is "locked" into the return type of the first application:

In this playground you will find both approaches. Just try the autocompletion for the calls of both a and b.
any updates on this? I have a function with 100+ overloads. needs this feature very much!
I have a function with 100+ overloads.
Good luck....
I have a function with 100+ overloads.
Good luck....
@Kingwl
sad...
I write 100+ overloads in one go
and finally, i find that the autocomplete has been totally destroyed.