Given the following interface and corresponding Yup schema. Is there a way for TypeScript to automatically infer the conditional function arguments (e.g. enabled and schema)?
import { object as yupObject, string as yupString, boolean as yupBoolean } from 'yup';
interface Foo {
enabled: boolean
name?: string
}
const fooSchema = yupObject().shape({
enabled: yupBoolean(),
name: yupString().when('enabled', (enabled, schema) => enabled ? schema.required() : schema)
})
I've tried yupObject()<Foo> and shape<Foo>(..) but neither helped. If it can't be done automatically, what is the appropriate type for schema in this case?