Review main Merged

86716[TASK] Type DOM query results via type arguments

Ayke Halder CR +2 V +2 Hard +307 −307 updated 10/23/26, 12:27

Commit message

Calls to querySelector() and closest() name the expected element type
as a type argument instead of a type assertion, and querySelectorAll()
does the same for its NodeListOf. Where a plain tag-name selector
already infers the type, the type and a variable annotation repeating
it are dropped.

On a selector that does not name the tag, such as a class or attribute
selector, the type argument is the same unchecked downcast the
assertion was. Narrowing these or checking the element is left to
follow-up patches.

The difference is null: the assertion removed it from the result, the
type argument keeps it. Without strictNullChecks the types are the
same. With it, a use without a null check would be reported instead of
hidden. This change adds no null checks.

Findings of the ESLint rule
@typescript-eslint/no-unnecessary-type-assertion drop from 394 to 92.

Review

  • Code review CR +2 Done
    • Benjamin Kott +2
    • Benjamin Franzke +1
  • Verified V +2 Done
    • Benjamin Kott +2
    • Benjamin Franzke +1
    • core-ci +1 CI

Issues 1

Files 99

Show 79 more files

Review log 1825

  1. Ayke Halder uploaded patch set 1 10/23/24, 16:09

  2. core-ci voted on patch set 1 V +1 10/23/24, 16:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68468

  3. Ayke Halder rebased onto patch set 2 V +1 10/23/24, 22:10

  4. core-ci voted on patch set 2 V +1 10/23/24, 22:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68489

  5. Benjamin Franzke commented on patch set 2 CR -2 10/24/24, 02:27

    You don't actually do that, as a lot of placing where `querySelector` is modified do not include the possibility to become `null`. Sorry, I can not trust this change at all. It looks quite good and I also like assertions via generics more than blunt type assertion, but they are still essentially the same and bring no improvement when used incorrectly. Also see https://review.typo3.org/c/Packages/TYPO3.CMS/+/86724/2#message-5f1e0f79226e22b15f80daff583ff5f488c6104f
  6. Ayke Halder commented on patch set 2 10/24/24, 10:05

    Reply

    > You don't actually do that, as a lot of placing where `querySelector` is modified do not include the possibility to become `null`. Sorry I don't really get the meaning of this sentence - language barrier. Is it A: "In general you don't actually do that, as a lot of placing where `querySelector` is modified, are known - by taking further knowledge from outside of the code into account - to never become `null`. Or is it B: "This change here does not do the implementation as described in its commit message."
  7. Benjamin Franzke commented on patch set 2 03/27/25, 13:20

    Reply

    Commit message describes B, but code does A. I understand the urge to apply "A" (because it is annoying to check every place for null without it ever happening), but it makes it hard to review, as we need to verify if your assumption that the selector will not resolve into `null` is true.
  8. Ayke Halder commented on patch set 2 03/27/25, 13:40

    Reply

    I'll try to check if I properly understand your point with these code examples. Example 1: not easily reviewable - missing null-check: ```js this.valueSlider = this.querySelector('input') as HTMLInputElement; new ThrottleEvent('input', this.handleRangeChange, 25).bindTo(this.valueSlider); . ``` Example 2: easily reviewable - null-check implemented: ```js this.valueSlider = this.querySelector('input') as HTMLInputElement|null; if (this.valueSlider !== null) { new ThrottleEvent('input', this.handleRangeChange, 25).bindTo(this.valueSlider); } . ```
  9. Ayke Halder commented on patch set 2 10/16/26, 09:07

    Reply

    No reply: @ben@bnf.dev please remove your double down-vote her.
  10. Benjamin Franzke commented on patch set 2 CR -1 10/16/26, 12:33

    Reply

    Sorry, but you didn't update the code and the code was blocked as is. Anyway, changing to -1 (so a push that fixes thing can remove the vote), so you're not blocked by me.
  11. Benjamin Kott uploaded patch set 3 CR -1 V +1 10/23/26, 10:30

  12. Benjamin Kott updated the commit message in patch set 4 10/23/26, 10:44

  13. Benjamin Kott updated the commit message in patch set 5 10/23/26, 10:45

  14. core-ci voted on patch set 3 V +1 10/23/26, 10:53 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112268

  15. core-ci voted on patch set 4 V +1 10/23/26, 10:58 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112271

  16. core-ci voted on patch set 5 V +1 10/23/26, 11:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112274

  17. Benjamin Franzke commented on patch set 5 10/23/26, 11:44

    Reply

    > You don't actually do that, as a lot of placing where querySelector is modified do not include the possibility to become null. Hey, me again. With the rewritten patch and by reviewing the changes (also your patchset 2 again) I noticed I was completely wrong here. I think I thought back then that `querySelector<FooElement>` causes the return type to be considered `FooElement` instead of `FooElement|null`, while null is preserved. I know that you wanted to express that, but I simply didn't get it. I'm sorry!
  18. Benjamin Franzke commented on patch set 5 10/23/26, 11:47

    system-information-menu.ts:64

    This unnecessary type declaration is removed in column-selector-button.ts, can it be removed in here (and similar cases) as well?
  19. Benjamin Kott uploaded patch set 6 V +1 10/23/26, 11:48

  20. Benjamin Kott uploaded patch set 7 10/23/26, 11:51

  21. core-ci voted on patch set 6 V +1 10/23/26, 12:00 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112286

  22. core-ci voted on patch set 7 V +1 10/23/26, 12:03 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112288

  23. Benjamin Franzke commented on patch set 7 CR +1 V +1 10/23/26, 12:06

    system-information-menu.ts:64 Reply

    Done
  24. Benjamin Kott voted on patch set 7 CR +2 V +2 10/23/26, 12:06

  25. Benjamin Kott merged patch set 8 10/23/26, 12:27