Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support set Schema output/input types explicitly #48

Open
5 tasks
moshest opened this issue Jul 21, 2020 · 0 comments
Open
5 tasks

Support set Schema output/input types explicitly #48

moshest opened this issue Jul 21, 2020 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@moshest
Copy link
Member

moshest commented Jul 21, 2020

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 to Person['age'])
@moshest moshest added the enhancement New feature or request label Jul 21, 2020
@moshest moshest changed the title Allow set Schema types explicitly Support set explicitly Schema types Jul 21, 2020
@moshest moshest changed the title Support set explicitly Schema types Support set explicitly Schema output/input types Jul 21, 2020
@moshest moshest changed the title Support set explicitly Schema output/input types Support set Schema output/input types explicitly Jul 21, 2020
@moshest moshest added this to the v1.2 milestone Jul 21, 2020
@moshest moshest removed this from the v1.2 milestone Oct 7, 2020
@moshest moshest added the help wanted Extra attention is needed label Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant