86724[TASK] Enable ESLint no-unnecessary-type-assertion
Commit message
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 3
Files 51
- Build/Sources/TypeScript/backend/bookmark/bookmark-manager.ts+2 −2
- Build/Sources/TypeScript/backend/element/breadcrumb.ts+6 −6
- Build/Sources/TypeScript/backend/element/combobox-element.ts+2 −2
- Build/Sources/TypeScript/backend/form-engine/container/flex-form-section-container.ts+1 −1
- Build/Sources/TypeScript/backend/form-engine/container/inline-control-container.ts+9 −9
- Build/Sources/TypeScript/backend/form-engine/element/extra/item-count.ts+1 −1
- Build/Sources/TypeScript/backend/form-engine/element/suggest/result-container.ts+1 −1
- Build/Sources/TypeScript/backend/form-engine/element/category-element.ts+3 −3
- Build/Sources/TypeScript/backend/form-engine/element/select-tree-element.ts+4 −4
- Build/Sources/TypeScript/backend/form-engine/field-wizard/localization-state-selector.ts+2 −2
- Build/Sources/TypeScript/backend/settings/editor.ts+2 −2
- Build/Sources/TypeScript/backend/tests/form-engine/element/select-tree-test.ts+1 −1
- Build/Sources/TypeScript/backend/tests/notification-test.ts+2 −2
- Build/Sources/TypeScript/backend/tree/page-position-select.ts+1 −1
- Build/Sources/TypeScript/backend/tree/tree.ts+1 −1
- Build/Sources/TypeScript/backend/utility/collapse-state-search.ts+1 −1
- Build/Sources/TypeScript/backend/viewport/content-navigation.ts+3 −3
- Build/Sources/TypeScript/backend/wizard/steps/finisher-step.ts+1 −1
- Build/Sources/TypeScript/backend/drag-uploader.ts+2 −2
- Build/Sources/TypeScript/backend/form-engine.ts+5 −5
Show 31 more files
- Build/Sources/TypeScript/backend/global-event-handler.ts+1 −1
- Build/Sources/TypeScript/backend/grid-editor.ts+1 −1
- Build/Sources/TypeScript/backend/modal.ts+2 −2
- Build/Sources/TypeScript/backend/multi-record-selection.ts+1 −1
- Build/Sources/TypeScript/backend/notification.ts+1 −1
- Build/Sources/TypeScript/backend/popover.ts+1 −1
- Build/Sources/TypeScript/backend/sortable-table.ts+2 −2
- Build/Sources/TypeScript/backend/tab.ts+1 −1
- Build/Sources/TypeScript/beuser/permissions.ts+2 −2
- Build/Sources/TypeScript/filelist/file-list.ts+1 −1
- Build/Sources/TypeScript/form/backend/form-editor/core.ts+1 −1
- Build/Sources/TypeScript/form/backend/form-editor/inspector-component.ts+2 −2
- Build/Sources/TypeScript/form/backend/form-editor/stage-component.ts+8 −9
- Build/Sources/TypeScript/form/backend/form-editor/view-model.ts+1 −1
- Build/Sources/TypeScript/install/module/environment/folder-structure.ts+1 −1
- Build/Sources/TypeScript/install/module/settings/local-configuration.ts+5 −5
- Build/Sources/TypeScript/install/module/upgrade/upgrade-docs.ts+1 −1
- Build/Sources/TypeScript/reactions/tests/field-map-element-test.ts+2 −2
- Build/Sources/TypeScript/recycler/recycler.ts+1 −1
- Build/Sources/TypeScript/rte-ckeditor/plugin/typo3-link.ts+2 −2
- Build/Sources/TypeScript/rte-ckeditor/ckeditor5.ts+2 −2
- Build/Sources/TypeScript/scheduler/form-engine/element/timing-options-element.ts+1 −1
- Build/Sources/TypeScript/scheduler/scheduler-add-group.ts+2 −2
- Build/Sources/TypeScript/scheduler/scheduler.ts+1 −1
- Build/Sources/TypeScript/workspaces/backend.ts+1 −1
- Build/Sources/TypeScript/workspaces/workspace-state.ts+1 −1
- Build/tests/playwright/e2e/form-engine/fal-metadata.spec.ts+1 −1
- Build/tests/playwright/e2e/install-tool/install-tool.spec.ts+6 −6
- Build/tests/playwright/e2e/media/file-clipboard.spec.ts+1 −1
- Build/tests/playwright/e2e/workspaces/workspaces-module.spec.ts+3 −3
- Build/eslint.config.mjs+1 −0
Review log 1518
-
Ayke Halder uploaded patch set 1 10/23/24, 23:31
-
Ayke Halder updated the commit message in patch set 2 10/23/24, 23:36
-
core-ci voted on patch set 1 V +1 10/23/24, 23:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68490
-
core-ci voted on patch set 2 V +1 10/23/24, 23:41 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68491
-
Benjamin Franzke commented on patch set 2 CR -2 10/24/24, 02:21
I like the intention of using no-unnecessary-type-assertions in order to cleanup the code by reducing unneeded `as` statements and better isolating the cases where types could not be infered, but I'm against the used approach: Example in Build/Sources/TypeScript/backend/global-event-handler.ts: The patch replaces `instanceof HTMLElement` with a generic type declaration to HTMLElement (which isn't actually guaranteed!) and thus makes our codebase less robust. `querySelector*` can also return SVGElements for generic selectors, therefore we need to be very cautious to not introduce makes the code less robust. Don't get me wrong, generics are fine in `querySelector*<>`, but only if they are 100% secure and correct (that means: When a tag name is eplicitly mentioned by the selector but the HTMLTagNameMap can not work automatically because additional argument filters are added), other than that they are no way better than a `as` statement. I also would like `strictNullChecks` to be enabled – see 67256: [WIP][TASK] Enable TypeScript strictNullChecks | https://review.typo3.org/c/Packages/TYPO3.CMS/+/67256 – but that's currently still a long way to go, and I don't think we should mangle our codebase to support it, we can never be sure that markup is correct and therefore would need to implemenet hundreds of (in reality) unnecessary checks for possibly broken markup. We need to reduce jquery-style code to webcomponents which makes the codebase more robust. Sorry, I'm not confident this changes improve the code and will therefore block the entire series. -
Ayke Halder commented on patch set 2 10/24/24, 13:21
Reply
> Example in Build/Sources/TypeScript/backend/global-event-handler.ts: > The patch replaces `instanceof HTMLElement` with a generic type declaration to HTMLElement (which isn't actually guaranteed!) and thus makes our codebase less robust. `querySelector*` can also return SVGElements for generic selectors, therefore we need to be very cautious to not introduce makes the code less robust. Here you have got a point: I just assumed in this case it is save - by knowledge from outside the JS-code - that the object is never an `SVGElement` and always an `HTMLElement`. -
Ayke Halder commented on patch set 2 10/24/24, 13:45
> Don't get me wrong, generics are fine in querySelector*<>, but only if they are 100% secure and correct (that means: When a tag name is eplicitly mentioned by the selector but the HTMLTagNameMap can not work automatically because additional argument filters are added), other than that they are no way better than a as statement. Here my point is that the following code using `as` might unintentionally drop any `null`-possibility - and thereby just covers errors that will uncover on run-time: ``` const someInput: HTMLInputElement = document.querySelector('input[data-foo]') as HTMLInputElement; ``` I prefere one of these: ``` const someInput = document.querySelector<HTMLInputElement>('input[data-foo]'); ``` ``` const someInput: HTMLInputElement|null = document.querySelector<HTMLInputElement>('input[data-foo]'); ``` ``` const someInput: HTMLInputElement = document.querySelector<HTMLInputElement>('input[data-foo]')!; ``` @ben@bnf.dev Please see all the iterations of type-assertions and decide which of these is the best to use. https://www.typescriptlang.org/play/?#code/PQKgsAUJCCA2sAID2AzBAXAFgUwdgHgIYC2ADrNgM4IBG2sSA7ggE5UCus6CAlgHYYcCAMZIyFdPQCevACbY+6HsMLwZAcwXYWhSbIQApAMoik8gFyRIAA1uRRfSt0pjsAST6l23ALwJZSMLsxAroAHQAjuzaUkb02MLoSCwAFADk-F7oaQCUANyQLiEeWQUQRe6e3mEAbqrRZbbWVhAeIoSUuHxIvFXcSDQAVgncPNQoSOx8sgA0CIQC2izJvNRYy4wC-IaEdZTCLDyk-QIsUwC0SiEIjDgChMLCVJT86gjWdbDR1mGQ5wB881gLgQExYCAARAARAD6wChEIAhC03ABZADyvFG1HUSDMgl080WLGW4LG-jG5EIUmw+m2ABUpKRsEYDkduLcFPNHs9XoJcB96thrJYIACELAeABrXDbCHQACMcIAQkrgABhJUQ35QCBwSQsPi6Hg1bDmBBuDmTWD6OgIXH4rCEhZ4EkrcmqNiEWQyWSU2DU2m9fmgngsJwS-jYSCc+6UF7qPh8rCyvrIIYjUXiyUy4PyhXAVUahXalpGHpYclLFaUTDW224FA8fC0nXoskCFSdBDnAncKXdRgUWSaUHLYjIbwveQh0QzhSUdhsai9p3cawVEreaw3HjwBAwvjYU0sGG0YV8TiwHdIU4XK7YGaQHjcFQCO2L0ikZedOkCRnMqyhzHLQMgEOQCQvrAMjsC8fBvBC3R8Ocl77h0nQsEot7IMyOhJCwELvIiIp-ICnS4PKABMKrURqtHQJRhaMeqlGlrqaKYi+qwIN0ziECguBJAgsG4JQUiKIQ+CQrC8KER0g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BhYLcCEuRG4mBCSTK-AuHU8UoHm11kqPgCTMlqLwYgUxKDVYWN8dw0J3VDz5OAYeRx+jnHLNWegSRuCzrSO-iknZPic5+OURk657CNkaPGnwY5hDllnIofww8VybnoA2fchhDMk5pNYWsrOeyUYHKyIDX5RdboG2BXwQFsSWqwhWZtFR8KfZ3K2V4p5-8Xns2oHCj5aiNH4r+eLU50SFlP11tRAltKwUQrJY8mFLsqUhIMZyplCtsWsvIbiwOILCXvJ5aSjxMj+XMPQW7fx4i6VBL9tY5FhDRXopLnqy2nKcWLIKbK7lnzFXJOhaqlOVq1HZLdrqyhBqIDFxFm6llFcgA -
Ayke Halder commented on patch set 2 10/16/26, 09:10
Reply
No reply: @ben@bnf.dev please remove your double down-vote here. -
Benjamin Franzke commented on patch set 2 CR -1 10/16/26, 12:32
Reply
you said in the other comment that "Here you have got a point", so I guess that needs to be adapted. anyway, I'll change to -1 so you're not blocked once reworked. -
Benjamin Franzke commented on patch set 2 10/23/26, 12:26
Reply
Preferred one is: ``` const someInput = document.querySelector<HTMLInputElement>('input[data-foo]'); ``` Reason: we want to write as less types as possible and takeover infered types as much as possible. (=best TypeScript)Reply
Right, therefore I suggest to avoid adding a type qualifier, if we don't know it for sure. That means a case like ``` let item = form.querySelector('[name=' + CSS.escape(name) + ']'); ``` Should just stay as-is. Reopening in order for Benji (who will rebase this patch) to consider this. -
Benjamin Kott uploaded patch set 3
CR -1V +110/23/26, 12:48 -
core-ci voted on patch set 3 V +1 10/23/26, 12:59 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112301
-
Benjamin Kott voted on patch set 3 CR +2 V +2 10/23/26, 13:21
-
Ayke Halder commented on patch set 3 CR -1 10/23/26, 13:22
Got one hit via regex to change: Build/Sources/TypeScript/backend/element/combobox-element.ts Line 475: ``` return assignedElements.find(el => el.tagName === 'INPUT') as HTMLInputElement | null; ``` Should be ``` return assignedElements.find<HTMLInputElement>(el => el.tagName === 'INPUT'); ``` -
Ayke Halder commented on patch set 3 CR 0 10/23/26, 13:34
Reply
Looks like this component might have more issues as `this.renderRoot` (and neither `this.shadowRoot`) might not exist in setup of `LitELement` life-cycle. So this might be another issue to solve. -
Benjamin Kott merged patch set 4 10/23/26, 13:58
-
Ayke Halder commented on patch set 3 10/23/26, 14:07
Reply Unresolved
`this.shadowRoot` did not have any issue here. My local environment had all build sources cleaned - and that issued an error - solved by: `Build/Scripts/runTests.sh -s build` ---- The issue: Here `find()` returns either an `HTMLInputElement` or `undefined` - that is not `null`. The return type of `getInput()` suggests `HTMLInputElement|null`. Actually the curent return values are `HTMLInputElement|null|undefined`. Solvable via 'Type Guard' - ̀is HTMLInputElement`: Option A: ``` return assignedElements.find((el): el is HTMLInputElement => el.tagName === 'INPUT'); // returns HTMLInputElement|undefined ``` Option B: ``` return assignedElements.find((el): el is HTMLInputElement => el.tagName === 'INPUT') ?? null; // returns HTMLInputElement|null ``` To not change the already defined return value of `getInput()`, select the second solution.