Reputation: 41
I am experimenting with function overloads in Typescript and I am getting the following error:
Error:(2, 5) TS2394: Overload signature is not compatible with function implementation.
I don't understand how to resolve this error. Any help would be appreciated.
create(key: string | TextKeys, reKey: string | TextKeys, params?: ObjectLiteral<string>, subkeys?: { [key: string]: string }, selector?: Selector): Either<EError, (AOutput | ROutput)[]>;
create(key: string | TextKeys, params?: ObjectLiteral<string>, subkeys?: { [key: string]: string }, selector?: Selector): Either<EError, AOutput>;
create(key: string | TextKeys, reKey?: string | TextKeys, params?: ObjectLiteral<string>, subkeys?: { [key: string]: string }, selector: Selector = selectRandom) {
const output: Either<EError, AOutput> = this.createAOutputs(key, params, subkeys).map(selector);
if (reKey !== undefined) {
return List.fromArray([output, this.createROutputs(reKey, params, subkeys)]).sequenceEither<EError, AOutput | ROutput>().map(arr => _.flatten(arr.toArray())) as Either<EError, (AOutput | ROutput)[]>;
} else {
return output;
}
}
Upvotes: 1
Views: 49
Reputation: 275997
I don't understand how to resolve this error. Any help would be appreciated.
Your last function signature MUST work for every possible overload. A quick hack to show what will work:
create(key: string | TextKeys, reKey: string | TextKeys, params?: ObjectLiteral<string>, subkeys?: { [key: string]: string }, selector?: Selector): Either<EError, (AOutput | ROutput)[]>;
create(key: string | TextKeys, params?: ObjectLiteral<string>, subkeys?: { [key: string]: string }, selector?: Selector): Either<EError, AOutput>;
create(...iWorkWithAllOptions:any[]) { // NOTICE
// implement
}
Upvotes: 1