If afterFind is defined, the return type should be a merge of schema and afterFind return type.
If afterFind is undefined, the return type should be the schema type.
const schema = { a: 'a' };
function mys<S, T>({ afterFind, schema }: { schema: S; afterFind?: (data: S) => T }) {
if (afterFind) {
return afterFind(schema);
} else {
return schema;
}
}
const s1 = mys({ schema });
const s2 = mys({ schema, afterFind: (data) => ({ ...data, b: 'b' }) });
I want s1 to be {a:'a'} and s2 to be {a:'a', b:'b'}
Right now s1 is unknown and s2 is {a: string} | {b: string; a: string;}