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
Invalid return type of "DebugElement.query" #22449
Comments
Would you be awesome and create a PR for us? |
I can follow this up. |
what is the status of this issue? noticed the PR was cancelled and we are now over 4 years on. it causes an issue when trying to use the lint rule 'no unnecessary condition' - i.e. the user may know that really the recommended advice should not be to deliberately throw, exceptions should be exceptional surely? |
We encountered issues with this in our unit tests. |
I just checked, A fixing of the type would require a migration schematics at least. I might give it a try since have I done a similar one for #48039. |
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
`DebugElement.query()` can return null, let's reflect that on the return type. This commit also provides a migration to insert non-null assertions after `DebugElement.query()` on existing code bases. Fixes angular#22449
Why does this have only 7 upvotes? Apparently only seven Angular users are writing tests properly 😩 Apparently all discussion is moved to the mentioned PR. Hopefully we see this landing in 2024. |
I'm submitting a...
Current behavior
DebugElement.query
declaresDebugElement
as the return type.Expected behavior
DebugElement.query
declaresDebugElement | null
as the return type.Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
The result of
DebugElement.query
can actually benull
.The error should be caught by the compiler since the programmer should assert that the element was found. This is especially true for
By.CSS
predicate as it seems that the likelihood of typos and mistakes is pretty high.The reason why this compiles without errors is that the return type of array indexing is
T
, notT | undefined
. This seems to be the intended behaviour of the TypeScript compiler.Environment
The text was updated successfully, but these errors were encountered: