Skip to content

feat: validateIf for validation options - #1579

Merged
braaar merged 23 commits into
typestack:developfrom
aoi-umi:develop
Feb 25, 2026
Merged

braaar merged 23 commits into
typestack:developfrom
aoi-umi:develop

Conversation

@aoi-umi

@aoi-umi aoi-umi commented Mar 11, 2022 •

Copy link
Copy Markdown
Contributor

Description

Add validateIf for validation options.
If you want to validate that condition by object, you can use validation validateIf.

ValidateIf will skip all other decorators, validation validateIf only effect the decorator that use this option

Checklist

  • the pull request title describes what this PR does (not a vague title like Update index.md)
  • the pull request targets the default branch of the repository (develop)
  • the code follows the established code style of the repository
    • npm run prettier:check passes
    • npm run lint:check passes
  • tests are added for the changes I made (if any source code was modified)
  • documentation added or updated
  • I have run the project locally and verified that there are no errors

Fixes

references #1455

Franco1312
Franco1312 previously approved these changes Mar 28, 2022
@braaar

braaar commented Dec 5, 2022

Copy link
Copy Markdown
Member

I think I prefer the skip or skipIf name for this option. I think validateIf is a bit confusing, since you can get it mixed up with the ValidateIf decorator.

@braaar

braaar commented Dec 5, 2022

Copy link
Copy Markdown
Member

Handy feature, though!

@braaar braaar left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good proposal, but I think the function should be normalized to match the predicate function used in ValidateIf.

This is how I see it being the most useful:

@Max(5, { validateIf: (o) => Boolean(o.someOtherProperty) })

I am now of the opinion that validateIf might be better than skip / skipIf.

@braaar

braaar commented Dec 15, 2023

Copy link
Copy Markdown
Member

See my recent comment in #1721

@braaar braaar left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in #1721, I think this decorator should have the same signature as ValidateIf.

The signature (value: any, validationArguments: ValidationArguments) => boolean; makes it unnecessarily cumbersome to do simple stuff like:
@IsUUID({ validateIf: o => o.type === "something" })

@aoi-umi

aoi-umi commented Jan 24, 2024

Copy link
Copy Markdown
Contributor Author

updated @braaar

@kevit-kelvin-mandlik

Copy link
Copy Markdown

@braaar Please merge this feature I am waiting for so long...

@kevit-kelvin-mandlik

Copy link
Copy Markdown

@braaar @aoi-umi What are you guys waiting upon this? Can we please move forward with this?

@aoi-umi

aoi-umi commented Mar 14, 2024

Copy link
Copy Markdown
Contributor Author

@braaar @aoi-umi What are you guys waiting upon this? Can we please move forward with this?

haha, i don't know either

@braaar

braaar commented Mar 19, 2024

Copy link
Copy Markdown
Member

We are discussing this feature internally right now. Hold on just a little longer, @kevit-kelvin-mandlik and @aoi-umi

@MaxKoldun

Copy link
Copy Markdown

@braaar Please merge this feature. I need it for my project.

@braaar

braaar commented Mar 4, 2025

Copy link
Copy Markdown
Member

@aoi-umi check the latest CI / Linters action. The codecov is still not happy with the sourceMap change. Could you try refactoring the code in some way (perhaps inverting or re-ordering some if-statements) to see if that makes codecov happy?

@aoi-umi

aoi-umi commented Mar 4, 2025

Copy link
Copy Markdown
Contributor Author

sorry i forget to run the lint, it is ok now? @braaar

@braaar

braaar commented Mar 4, 2025

Copy link
Copy Markdown
Member

Thanks. I'm still hesitant to merge due to the codecov problem. I'm not a test coverage hawk, I'm just worried that it might be catching something we aren't catching.

@braaar

braaar commented Feb 25, 2026

Copy link
Copy Markdown
Member

I think it's time.

@github-actions

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

9 participants