My attempt to define an overload for my function using a Partial interface overloading is causing typescript to select the incorrect overload
interface Args {
_id: string;
name: string;
}
interface Result {
_id: string;
name: string;
}
function myFunction(arg: Args): Result;
function myFunction(arg: Partial<Args>): Partial<Result> {
return arg;
}
// The error message states that '{ _id: string; }' cannot be assigned to type 'Args'.
// It points out that property 'name' is missing in '{ _id: string; }' which is required in 'Args'
myFunction({ _id: 'aa' });
Even trying to use
myFunction({ _id: 'aa' } as Partial<Args>);
does not provide a solution
Is there a way to make this work properly?