Given this function:
export const combineValidators = <Input extends { [P in keyof Input]: (val: string) => Err }, Err>(
validators: Input
) => (values: { [P in keyof Input]?: unknown }): { [P in keyof Input]: Err } => {
// Ignore implementation.
return {} as { [P in keyof Input]: Err };
};
And this usage:
const validator = combineValidators({
name: (val) => val ? undefined : 'error',
email: (val) => val ? undefined : 'error'
});
const errors = validator({
name: 'Lewis',
email: '[email protected]'
});
I would expect TypeScript to be able to infer the return type as:
// Expected: `errors` to be inferred as:
interface Ret {
name: string | undefined;
email: string | undefined;
}
However it's inferred as:
// Actual: `errors` inferred as:
interface Ret {
name: {};
email: {};
}
I've created a live example in the TypeScript playground demonstrating the issue.
Can anybody help?