Skip to content

Validator Alias With String Literals #4

Description

@zeluisping

Is your feature request related to a problem? Please describe.
Having to write itz.AsOptionalNumber all the time is really cumbersome, there needs to be a simpler and cleaner way.

Describe the solution you'd like
The solution would be to introduce string literals back and be able to use 'as number?' as if it was a validator. Internally the same validators would still be used.

Describe alternatives you've considered
Really I don't think there's any simpler than that.

Additional context
The new possible validation values would be:

  • Primitives: 'string', 'number', 'object', 'undefined', 'null', and 'boolean'
  • Primitive Arrays: 'string[]', 'number[]', 'object[]', 'undefined[]', 'null[]', and 'boolean[]'

Before

const Headers = itz.A({
    UserDomain: itz.String,
    WholeFamily: itz.AsOptionalBoolean,
    SomethingElse: itz.Either(itz.String, itz.AsNumber, itz.Undefined),
});

After

const Headers = itz.A({
    UserDomain: 'string',
    WholeFamily: 'as boolean?',
    SomethingElse: itz.Either('string', 'as number', 'undefined'),
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions