Skip to content

Conversation

ehenon
Copy link

@ehenon ehenon commented Sep 18, 2025

Description

As mentioned/discussed in some issues and PRs, proposal to add a new decorator based on the same philosophy as @IsOptional(), but filtering only values that are actually missing (=== undefined). Equivalent to @ValidateIf((o, v) => v !== undefined), but more direct and explicit.

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

References

references #491, #2615, #686

@ehenon ehenon changed the title feat: add @IsActuallyOptional() decorator filtering only missing undefined values feat: add @IsStrictlyOptional() decorator filtering only missing undefined values Sep 19, 2025
@AntonioJRM1998
Copy link

I think it makes more sense to use this decorator in the way I suggested. My view of “optional” in a DTO is: if the property is not present in the request body, validation should be skipped; if it is present (even if null or undefined), validation should run.

Using propertyName in object achieves this behavior:

Property absent → skip validation

Property present → run validation

This way, the decorator better reflects the semantic meaning of “optional” and avoids the confusion of skipping validation only for undefined, which doesn’t fully cover real-world use cases.

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

Successfully merging this pull request may close these issues.

2 participants