I have a function that can receive two different object signatures as an argument. How do I type that?
i.e.
fn({ a: 'a', c: 'c' })
fn({ b: 2, c: 'c' })
however I tried to define the argument types, TS complains a and b do not exist on that type (only c which exists on both is fine)
export type IUploadImageArgs =
| {
uri: string;
type: string;
path: string;
}
| {
path: string;
file: any;
};
const uploadImage = async ({ file, path }: IUploadImageArgs) => {
}
// Property 'file' does not exist on type 'IUploadImageArgs'
Side note: This is for a react native + web project, a function that abstracts the uploading of files, in which the web version accepts the file itself, while the native version accepts the local path of the file.
Thanks!
function fn(args:{a:string, c:string}|{b:number, c:string})?