Review main Merged

95425[TASK] Guard nullable values in TypeScript

Benjamin Kott CR +2 V +2 Hard +307 −276 updated 11/18/26, 17:33

Commit message

Properties initialised with null now declare it in their type, and a
value the types report as possibly missing is guarded or given a
fallback. This prepares for strictNullChecks; the modules behave the
same with the markup they are rendered with.

Values the module's own markup guarantees get a non-null assertion
once strictNullChecks is enabled. Until then
no-unnecessary-type-assertion reports every such assertion, so they
are added together with the option.

Review

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

Issues 2

Files 121

Show 101 more files

Review log 2635

Show 610 earlier messages
  1. Benjamin Kott uploaded patch set 1 08/26/26, 13:09

  2. core-ci voted on patch set 1 V +1 08/26/26, 13:20 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/107138

  3. Benjamin Kott marked it work in progress 08/26/26, 13:24

  4. Benjamin Kott uploaded patch set 2 V +1 10/15/26, 16:16

  5. core-ci voted on patch set 2 V +1 10/15/26, 16:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111227

  6. Benjamin Kott updated the commit message in patch set 3 V +1 10/15/26, 21:02

  7. Benjamin Kott marked it ready for review 10/15/26, 21:02

  8. core-ci voted on patch set 3 V -1 10/15/26, 21:45 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111268

  9. Benjamin Kott rebased onto patch set 4 V -1 10/16/26, 07:45

  10. core-ci voted on patch set 4 V -1 10/16/26, 08:21 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111316

  1. Benjamin Kott rebased onto patch set 5 V -1 10/16/26, 09:26

  2. Ayke Halder commented on patch set 5 10/16/26, 09:42

    Feels like I already worked two years ago on this... * 86716: [TASK] Prepare for ESLint `@typescript-eslint/no-unnecessary-type-assertion` rule and `strictNullChecks` | https://review.typo3.org/c/Packages/TYPO3.CMS/+/86716 * 86724: [TASK] Implement ESLint `@typescript-eslint/no-unnecessary-type-assertion` rule | https://review.typo3.org/c/Packages/TYPO3.CMS/+/86724 ---- So please double-check all newly introduced changes by temporarily activating `strictNullChecks` and additionally `Build/eslint.config.mjs`: ``` rules: { "@typescript-eslint/no-unnecessary-type-assertion": "error", } ``` This should highlight all unnecessary code changes inside your IDE. ---- Overview on TypeScript error reporting - split up on cases by different type-checks: https://www.typescriptlang.org/play/?#code/PQKgsAUJCCA2sAID2AzBAXAFgUwdgHgIYC2ADrNgM4IBG2sSA7ggE5UCus6CAlgHYYcCAMZIyFdPQCevACbY+6HsMLwZAcwXYWhSbIQApAMoik8gFyRIAA1uRRfSt0pjsAST6l23ALwJZSMLsxAroAHQAjuzaUkb02MLoSCwAFADk-F7oaQCUANyQLiEeWQUQRe6e3mEAbqrRZbbWVhAeIoSUuHxIvFXcSDQAVgncPNQoSOx8sgA0CIQC2izJvNRYy4wC-IaEdZTCLDyk-QIsUwC0SiEIjDgChMLCVJT86gjWdbDR1mGQ5wB881gLgQExYCAARAARAD6wChEIAhC03ABZADyvFG1HUSDMgl080WLGW4LG-jG5EIUmw+m2ABUpKRsEYDkduLcFPNHs9XoJcB96thrJYIACELAeABrXDbCHQACMcIAQkrgABhJUQ35QCBwSQsPi6Hg1bDmBBuDmTWD6OgIXH4rCEhZ4EkrcmqNiEWQyWSU2DU2m9fmgngsJwS-jYSCc+6UF7qPh8rCyvrIIYjUXiyUy4PyhXAVUahXalpGHpYclLFaUTDW224FA8fC0nXoskCFSdBDnAncKXdRgUWSaUHLYjIbwveQh0QzhSUdhsai9p3cawVEreaw3HjwBAwvjYU0sGG0YV8TiwHdIU4XK7YGaQHjcFQCO2L0ikZedOkCRnMqyhzHLQMgEOQCQvrAMjsC8fBvBC3R8Ocl77h0nQsEot7IMyOhJCwELvIiIp-ICnS4PKABMKrURqtHQJRhaMeqlGlrqaKYi+qwIN0ziECguBJAgsG4JQUiKIQ+CQrC8KER0gjksQPDqJg3BTPwkiKDwt6qNBpgniG1bgr2NDeIZbpktQTh7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VYWN8dw0J3VDz5OAYeRx+jnHLNWegSRuCzrSO-iknZPic5+OURk657CNkaPGnwY5hDllnIofww8VybnoA2fchhDMk5pNYWsrOeyUYHKyIDX5RdboG2BXwQFsSWqwhWZtFR8KfZ3K2V4p5-8Xns2oHCj5aiNH4r+eLU50SFlP11tRAltKwUQrJY8mFLsqUhIMZyplCtsWsvIbiwOILCXvJ5aSjxMj+XMPQW7fx4i6VBL9tY5FhDRXopLnqy2nKcWLIKbK7lnzFXJOhaqlOVq1HZLdrqyhBqIDFxFm6llFcgA

    main.ts:144

    Just one example: Here I'd go for ``` const searchField = document.querySelector<HTMLInputElement>(ExtensionManagerIdentifier.searchField); ``` Which is absolute identical to your code but better readable. ---- See the TypeScript playground example below: * Your code: "Type-assertions on left side of assignment - including `null`" * My suggestion: "Type-assertions only on right side of assignment" https://www.typescriptlang.org/play/?#code/PQKgsAUJCCA2sAID2AzBAXAFgUwdgHgIYC2ADrNgM4IBG2sSA7ggE5UCus6CAlgHYYcCAMZIyFdPQCevACbY+6HsMLwZAcwXYWhSbIQApAMoik8gFyRIAA1uRRfSt0pjsAST6l23ALwJZSMLsxAroAHQAjuzaUkb02MLoSCwAFADk-F7oaQCUANyQLiEeWQUQRe6e3mEAbqrRZbbWVhAeIoSUuHxIvFXcSDQAVgncPNQoSOx8sgA0CIQC2izJvNRYy4wC-IaEdZTCLDyk-QIsUwC0SiEIjDgChMLCVJT86gjWdbDR1mGQ5wB881gLgQExYCAARAARAD6wChEIAhC03ABZADyvFG1HUSDMgl080WLGW4LG-jG5EIUmw+m2ABUpKRsEYDkduLcFPNHs9XoJcB96thrJYIACELAeABrXDbCHQACMcIAQkrgABhJUQ35QCBwSQsPi6Hg1bDmBBuDmTWD6OgIXH4rCEhZ4EkrcmqNiEWQyWSU2DU2m9fmgngsJwS-jYSCc+6UF7qPh8rCyvrIIYjUXiyUy4PyhXAVUahXalpGHpYclLFaUTDW224FA8fC0nXoskCFSdBDnAncKXdRgUWSaUHLYjIbwveQ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XD3YcywWwnB6ACHiz4WLKEZDpZR0NgxMRCCpH0IdnItBCjkba1LgxLRz9KK6OETjK2RjaEmNtsg2RqDk4AM1pgmhqiTpnTzmAlqVs7FhIcYI020CLYsVcYE9xnjGHeKWqnAJEj2GcKsRoliESiZRIrkXcAEAa7uU8vGbyTdqDYQoN3WWoVcDhX7omRBvZ+DCC+H6I+18rzNFKcPUeBhYLcCEuRG4mBCSTK-AuHU8UoHm11kqPgCTMlqLwYgUxKDVYWN8dw0J3VDz5OAYeRx+jnHLNWegSRuCzrSO-iknZPic5+OURk657CNkaPGnwY5hDllnIofww8VybnoA2fchhDMk5pNYWsrOeyUYHKyIDX5RdboG2BXwQFsSWqwhWZtFR8KfZ3K2V4p5-8Xns2oHCj5aiNH4r+eLU50SFlP11tRAltKwUQrJY8mFLsqUhIMZyplCtsWsvIbiwOILCXvJ5aSjxMj+XMPQW7fx4i6VBL9tY5FhDRXopLnqy2nKcWLIKbK7lnzFXJOhaqlOVq1HZLdrqyhBqIDFxFm6llFcgA
  3. core-ci voted on patch set 5 V +1 10/16/26, 10:04 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111331

  4. Ayke Halder commented on patch set 5 10/16/26, 10:27

    Some more suggestions. Especially have a look at how a type is easily added to `event.target`: ``` element.addEventListener(this.eventName, (e: Event & { target?: HTMLElement }) ```

    char-counter.ts:23

    ```suggestion private targetElement: HTMLInputElement | HTMLTextAreaElement | null = null; ```

    modal.ts:150

    ```suggestion @state() templateResultContent: TemplateResult | Element | DocumentFragment | null = null; ```

    regular-event.ts:44

    ```suggestion element.addEventListener(this.eventName, (e: Event & { target?: HTMLElement }): void => { for (let targetElement = e.target; targetElement && targetElement !== this.boundElement; targetElement = targetElement.parentElement) { ```

    repository.ts:196

    ```suggestion const searchField = document.querySelector<HTMLInputElement>('.typo3-extensionmanager-searchTerForm input[type="search"]'); ```

    update.ts:57

    ```suggestion const extensionTable = document.querySelector<HTMLTableElement>(ExtensionManagerUpdateIdentifier.extensionTable); ```

    default_frontend.ts:55

    ```suggestion document.addEventListener(event, function(evt: Event & { target?: Node }) { for (let node = evt.target; node; node = node.parentNode !== document ? node.parentNode : null) { ```
  5. Ayke Halder commented on patch set 5 CR -1 10/16/26, 10:55

    No functional changes or bug fixes here

    text-normalizer.ts:83

    This must not be a new feature or bug fix here. ```suggestion .replace(TextNormalizer.latinExpansionPattern, (letter: string): string => TextNormalizer.latinExpansions.get(letter) ?? ''); ```
  6. Benjamin Kott uploaded patch set 6 CR -1 V +1 10/23/26, 14:49

  7. Benjamin Kott commented on patch set 6 10/23/26, 15:04

    Reply

    It was not the intention, to not respect or produce double work here. BNF already worked on this before that, and we kept pushing it back and simply decided to give it a fresh shot. We finished both patches and i rebased the chain on these.

    char-counter.ts:23 Reply

    Done

    modal.ts:150 Reply

    Done

    text-normalizer.ts:83 Reply

    Done

    repository.ts:196 Reply

    Done

    update.ts:57 Reply

    Done
  8. Benjamin Kott commented on patch set 6 10/23/26, 15:07

    Reply

    Acknowledged
  9. Benjamin Kott uploaded patch set 7 10/23/26, 15:42

  10. core-ci voted on patch set 6 V -1 10/23/26, 15:44 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112323

  11. Benjamin Kott marked it work in progress 10/23/26, 15:49

  12. core-ci voted on patch set 7 V -1 10/23/26, 16:25 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112343

  13. Benjamin Kott uploaded patch set 8 V -1 11/18/26, 10:59

  14. Benjamin Kott commented on patch set 5 11/18/26, 11:23

    Reply

    Thanks. The querySelector<T>() form is applied throughout. For the event.target typing see the replies in regular-event.ts and default_frontend.ts.

    regular-event.ts:44 Reply

    I kept the cast. `Event & { target?: HTMLElement }` makes `target` a plain `HTMLElement` (the intersection drops `null`), so the inferred loop variable no longer admits `null`. With strictNullChecks enabled later in this chain, `targetElement = targetElement.parentElement` then fails to compile. `as HTMLElement | null` asserts the same element type but stays honest about the end of the walk.

    main.ts:144 Reply

    Done, it uses querySelector<HTMLInputElement>() now.

    default_frontend.ts:55 Reply

    Same reasoning as in regular-event.ts: with `{ target?: Node }` the loop variable becomes `Node` without `null`, and `node = ... ? node.parentNode : null` no longer compiles under strictNullChecks. So the cast to `Node | null` stays.
  15. core-ci voted on patch set 8 V +1 11/18/26, 11:28 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/114855

  16. Benjamin Kott commented on patch set 5 11/18/26, 12:02

    regular-event.ts:44 Reply

    Kept the cast, see the reply on this line.

    main.ts:144 Reply

    Done.

    default_frontend.ts:55 Reply

    Kept the cast, see the reply on this line.
  17. Benjamin Kott commented on patch set 8 11/18/26, 12:03

    This change is ready for review.
  18. Ayke Halder commented on patch set 8 11/18/26, 13:49

    default_frontend.ts:55 Reply

    Please try removing the type-assertion that forces a wrong type by excluding `null` and `undefined`. `evt.target as Node`. After type-assertion is removed: How can the type be fixed? In: ``` for (let node: Node | null = evt.target as Node; node; node = node.parentNode !== document ? node.parentNode : null) { . ```
  19. Ayke Halder commented on patch set 8 11/18/26, 14:16

    default_frontend.ts:55 Reply

    Sorry, it is already fine now! Just rechecked this locally.
  20. Ayke Halder commented on patch set 8 11/18/26, 14:25

    default_frontend.ts:55 Reply

    And for sake of completeness, this works: `(function(evt: Event & {target: Node | null}) {…}) as EventListener` `((evt: Event & {target: Node | null}) => {…}) as EventListener` But it looks to complex, so better don't use: ``` document.addEventListener(event, (function(evt: Event & {target: Node | null}) { for (let node = evt.target; node; node = node.parentNode !== document ? node.parentNode : null) { […] } }) as EventListener); ```
  21. Ayke Halder rebased onto patch set 9 V +1 11/18/26, 14:47

  22. core-ci voted on patch set 9 V +1 11/18/26, 15:00 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/114879

  23. Benni Mack commented on patch set 9 CR +1 V +1 11/18/26, 17:16

    lets get it in before we get more merge conflicts.
  24. Benjamin Kott voted on patch set 9 CR +2 V +2 11/18/26, 17:33

  25. Benjamin Kott merged patch set 10 11/18/26, 17:33