Allow Remote Form schemas to have additional input types to what forms may receive
types / typescriptforms
### Describe the problem
At the moment, the remote `form` typings are pretty strict about their schema's input types. For example, the following example is currently not allowed, even though it doesn't produce a problem at runtime:
```ts
const numberish = v.union([v.number(), v.bigint()])
export const foo = form(
v.object({
bar: numberish,
^^^^^^^^^
// Property bar is incompatible with index signature. Type number | bigint
// is not assignable to type MaybeArray<string | number | boolean | RemoteFormInput | File>
}),
async (data) => { ... },
)
```
In my apps, I have some quite specialised schemas that sometimes happen to _additionally_ allow input that remote function can't give (and thus disallow). I use schemas more many different things, and I'd like to reuse them as much as possible.
As another example, it feels weird that `v.optional(...)` is allowed, but `v.nullish(...)` isn't – even though it's basically `v.optional(v.nullable(...))`. It feels weird because I don't understand why remote forms have to police that my schema handles other inputs.
It's also already allowed to NOT handle possible inputs.
### Describe the proposed solution
The form should allow schemas as long as there is an overlap with the types that the form can possibly send. To pick up the example from above:
```ts
export const foo = form(
v.object({
// Should be allowed, because there's overlap between
// `number | bigint` and `MaybeArray<string | number | boolean | RemoteFormInput | File>`
bar: v.union([v.number(), v.bigint()]),
// Should be forbidden, because there's no overlap between
// `date | bigint` and `MaybeArray<string | number | boolean | RemoteFormInput | File>`
bar2: v.union([v.date(), v.bigint()]),
}),
async (data) => { ... },
)
```
### Alternatives considered
I could implement separate schemas for remote forms and the rest of my app, but this seems error prone and a bit annoying.
### Importance
would make my life easier
### Additional Information
This is extracted from https://github.com/sveltejs/kit/issues/15249#issuecomment-4745841931, which was closed by the original author, and I think my particular problem was only half related anyway.
0 条评论