Commit 2ddb8bd
authored
fix(common): mark parse date pipe options as optional (#17780)
`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`.1 parent 10ee9b3 commit 2ddb8bd
2 files changed
Lines changed: 22 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
44 | 47 | | |
45 | 48 | | |
46 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
61 | 79 | | |
0 commit comments