Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Better Typings for constraints #302

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

mauricedoepke
Copy link

@mauricedoepke mauricedoepke commented Jul 30, 2019

I have added typings for constraints. This PR differs in some ways from #258:

  • it is stricter for length constraint: mi/max may not be used together with "s
  • it is stricter for the numericality constraint: equal may not be used together with greater/less
  • allows custom messages to be optional
  • allows any instead of only Date for earlieast/latest in datetime constraint. According to the docs earliest/latest are parse by the parse function, Thus it makes sense to allow the user any values as long as he can parse them
  • allows functions that return the message
  • allows functions that return the validation constraint
  • adds return type for the validation function

I did not use Record<string, ConstraintsTypes> as you suggested in the other PR. I think an index signature is better in this case because with the index signature we can indicate that the first string is meant to be an attributeName. This is not possible with records. Aside from that, they are the same regarding type safety.

@coveralls
Copy link

coveralls commented Jul 30, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling efcccea on mauricedoepke:master into c64df5d on ansman:master.

@zepatrik zepatrik mentioned this pull request Aug 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants