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

feat(mapped-types): add skip null properties option to partial type #1274

Merged

Conversation

tf3
Copy link
Contributor

@tf3 tf3 commented Jan 11, 2024

With this change, you can create a partial class which does not ignore validations on null properties, but ignores validations on undefined properties. Previously, every class created with PartialType ignored validations on null properties, which may be undesired if you are defining the DTO for a PATCH endpoint. If the option is not defined, the behaviour is unchanged from the previous behaviour.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

PartialType will return a class for which validations are ignored null properties (in addition to undefined properties).

What is the new behavior?

PartialType can optionally return a class for which validations are ignored only for undefined properties, not null properties. This can be useful if you are creating a DTO for a PATCH endpoint: there may be a certain field, say name, that should not be null, but which doesn't need to be included in PATCH updates.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This feature was discussed here. Note that we will want to make a similar change to the @nestjs/swagger code.

With this change, you can create a partial class which disallows null values, but allows
undefined values. Previously, every class created with PartialType allowed null values for
every property, which may be undesired if you are defining the DTO for a PATCH endpoint.
If the option is not defined, the behaviour is unchanged from the previous behaviour.
@kamilmysliwiec kamilmysliwiec merged commit 8b26440 into nestjs:master Feb 7, 2024
@kamilmysliwiec kamilmysliwiec added the enhancement New feature or request label Feb 7, 2024
@kamilmysliwiec
Copy link
Member

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants