computed-types
computed-types copied to clipboard
Support set Schema output/input types explicitly
In cases we already have the schema types defined, it would be a nice to have the Schema
receive the output type and optionally the input type explicitly.
Motivation: Validate that the validator actually implement the given types exactly.
For example:
type Person {
name: string;
age: number;
}
type PersonInput {
name: unknown;
age: unknown;
}
const PersonSchema = Schema<Person, PersonInput>({
name: unknown.string(),
age: unknown.number(),
);
// typeof PersonSchema == (input: PersonInput) => Person;
I tried to implement it from the beginning, but I couldn't find a way to make it work nicely without breaking some functionality. Maybe it's time to give it another try.
Considerations:
- [ ] Support
Schema
without any type arguments - [ ] Support giving only output type
- [ ] Support giving both output and input types
- [ ] Support
async
validators - [ ] Bonus: Support IDE when Ctrl+Click on scheme field (ie. clicking on schema
age:
will jump toPerson['age']
)