`forward(partialCheck(...))` fails to infer valid paths on merged generic object schemas
question
## Summary
`forward(partialCheck(...))` does not typecheck cleanly when used on a `strictObject` built from generic object entries merged with shared entries.
At runtime the schema behaves as expected, but TypeScript rejects the pattern in a way that makes reusable cross-field validation helpers difficult to express without casts, `rawCheck`, or duplicating the validation inline.
## Valibot version
- `valibot@1.3.1`
## Minimal reproduction
```ts
import * as v from "valibot";
const sharedEntries = {
enabled: v.optional(v.boolean()),
config: v.optional(v.string()),
};
function createSchema<TEntries extends v.ObjectEntries>(entries: TEntries) {
return v.pipe(
v.strictObject({
...entries,
...sharedEntries,
}),
v.forward(
v.partialCheck(
[["config"], ["enabled"]],
(input) => input.config === undefined || input.enabled === true,
"config is only allowed when enabled is true",
),
["config"],
),
);
}
createSchema({
id: v.string(),
label: v.string(),
});
```
## Actual result
TypeScript reports errors like:
```txt
Type '["config"]' is not assignable to type 'ValidPath<...>'
Type '["enabled"]' is not assignable to type 'ValidPath<...>'
Property 'config' does not exist on type 'DeepMerge<...>'
Property 'enabled' does not exist on type 'DeepMerge<...>'
```
## Expected result
I would expect this to typecheck, because:
- the final schema clearly contains both `config` and `enabled`
- those are valid top-level paths
- the predicate only references fields that are present in the merged object schema
3 条评论