fix(common): mark parse date pipe options as optional - #17780
Merged
kamilmysliwiec merged 1 commit intoSep 17, 2026
Merged
kamilmysliwiec merged 1 commit into
kamilmysliwiec merged 1 commit into
Conversation
`ParseDatePipe` is the only built-in pipe whose constructor argument is not
decorated with `@Optional()`. The `= {}` default does not cover this, because
the injector never calls the constructor with a missing argument: it resolves
parameters from `design:paramtypes`, which is `Object` for an interface, and
then fails to find a provider for it.
As a result, passing the pipe by class — the form used throughout the docs for
every other pipe — throws at bootstrap:
@get()
find(@query('v', ParseDatePipe) v: Date) {}
Nest can't resolve dependencies of the ParseDatePipe (?). Please make sure
that the argument at index [0] is available in the current module.
`@Query('v', ParseBoolPipe)` works, so the failure looks arbitrary and the only
workaround is to instantiate the pipe manually (`new ParseDatePipe()`).
Decorate the argument with `@Optional()` so the injector passes `undefined` and
the existing default value applies. Also widen `private` to `protected` to match
every other pipe and this class's own `exceptionFactory`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
ParseDatePipeis the only built-in pipe whose constructor argument is not decorated with@Optional():The
= {}default looks like it covers the missing-argument case, but it does not. The injectornever calls the constructor with a missing argument — it resolves constructor parameters from
design:paramtypes, which isObjectfor an interface, and then looks for a provider for thattoken. Without the optional marker, resolution fails before the default value can ever apply.
So passing the pipe by class, the form the docs use for every other pipe, throws at bootstrap:
Reproduction
Minimal repro against
master— a single spec is enough, since the failure happens while themodule is being compiled:
ParseBoolPipecompiles,ParseDatePipedoes not. Identical usage, different outcome — so thefailure looks arbitrary from the outside, and the only workaround is to instantiate the pipe by
hand (
@Query('v', new ParseDatePipe())).The same underlying metadata gap is visible directly:
What is the new behavior?
ParseDatePipe'soptionsargument is decorated with@Optional(), so the injector passesundefinedand the existing= {}default applies. Passing the pipe by class now works exactlylike every other built-in pipe:
private readonly optionsis also widened toprotected readonly options, matching every otherpipe as well as this class's own
exceptionFactory, so the pipe can be subclassed like its siblings.Two regression tests were added to
parse-date.pipe.spec.ts, following the existingoptional.decorator.spec.tspattern:optionsargument is marked optional for the injectorVerified locally: the repro above fails on
masterand passes with this change, and the full unitsuite is green (
280files,2949tests) withnpm run lintclean.Does this PR introduce a breaking change?
Adding
@Optional()only widens what the injector accepts, andprivate→protectedonly widensmember visibility. Existing usage — including
new ParseDatePipe({ ... })and passing an instanceinto a param decorator — is unaffected.
Other information
The fix is deliberately kept to the one pipe that is inconsistent; all other built-in pipes already
carry
@Optional().