From c7f4ca265376700b56b4d0bdd4c879dd9915d1cf Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 22 Jan 2025 08:11:51 +0100 Subject: Enable Typescript `noImplicitAny` (#33322) Enable `noImplicitAny` and fix all issues. --------- Co-authored-by: wxiaoguang --- web_src/js/components/DashboardRepoList.vue | 16 +++---- web_src/js/components/DiffCommitSelector.vue | 29 +++++++++--- web_src/js/components/DiffFileList.vue | 14 +++--- web_src/js/components/DiffFileTree.vue | 11 ++--- web_src/js/components/DiffFileTreeItem.vue | 18 ++++---- web_src/js/components/PullRequestMergeForm.vue | 8 ++-- web_src/js/components/RepoActionView.vue | 44 ++++++++++++------ web_src/js/components/RepoActivityTopAuthors.vue | 1 + web_src/js/components/RepoBranchTagSelector.vue | 4 +- web_src/js/components/RepoContributors.vue | 20 ++++---- .../js/components/ScopedAccessTokenSelector.vue | 2 +- web_src/js/features/admin/common.ts | 2 +- web_src/js/features/citation.ts | 4 ++ web_src/js/features/common-button.ts | 18 ++++---- web_src/js/features/common-fetch-action.ts | 5 +- web_src/js/features/common-form.ts | 4 +- web_src/js/features/comp/ComboMarkdownEditor.ts | 41 ++++++++++------- web_src/js/features/comp/EditorMarkdown.ts | 8 ++-- web_src/js/features/comp/EditorUpload.ts | 53 ++++++++++++---------- web_src/js/features/comp/QuickSubmit.ts | 2 +- web_src/js/features/comp/SearchUserBox.ts | 2 +- web_src/js/features/comp/TextExpander.ts | 7 +-- web_src/js/features/contextpopup.ts | 4 +- web_src/js/features/copycontent.ts | 2 +- web_src/js/features/dropzone.ts | 18 +++++--- web_src/js/features/emoji.ts | 6 +-- web_src/js/features/file-fold.ts | 6 +-- web_src/js/features/heatmap.ts | 2 +- web_src/js/features/imagediff.ts | 18 ++++---- web_src/js/features/install.ts | 3 +- web_src/js/features/org-team.ts | 2 +- web_src/js/features/pull-view-file.ts | 8 ++-- web_src/js/features/repo-common.ts | 8 ++-- web_src/js/features/repo-diff.ts | 2 +- web_src/js/features/repo-editor.ts | 2 +- web_src/js/features/repo-findfile.ts | 14 +++--- web_src/js/features/repo-home.ts | 6 +-- web_src/js/features/repo-issue-content.ts | 4 +- web_src/js/features/repo-issue-edit.ts | 14 +++--- web_src/js/features/repo-issue-list.ts | 9 ++-- .../js/features/repo-issue-sidebar-combolist.ts | 6 +-- web_src/js/features/repo-issue.ts | 20 ++++---- web_src/js/features/repo-migrate.ts | 6 +-- web_src/js/features/repo-new.ts | 4 +- web_src/js/features/repo-settings.ts | 6 +-- web_src/js/features/repo-wiki.ts | 2 +- web_src/js/features/stopwatch.ts | 6 +-- web_src/js/features/tablesort.ts | 2 +- web_src/js/features/tribute.ts | 36 ++++++--------- web_src/js/features/user-auth-webauthn.ts | 4 +- web_src/js/markup/asciicast.ts | 1 + web_src/js/markup/html2markdown.ts | 6 ++- web_src/js/modules/fomantic/dropdown.ts | 24 +++++----- web_src/js/standalone/devtest.ts | 2 +- web_src/js/svg.ts | 2 +- web_src/js/types.ts | 2 + web_src/js/utils.ts | 4 +- web_src/js/utils/dom.ts | 4 +- web_src/js/utils/image.test.ts | 2 +- web_src/js/utils/time.ts | 2 +- web_src/js/webcomponents/absolute-date.ts | 2 +- 61 files changed, 319 insertions(+), 265 deletions(-) (limited to 'web_src/js') diff --git a/web_src/js/components/DashboardRepoList.vue b/web_src/js/components/DashboardRepoList.vue index 40ecbba5e3..876292fc94 100644 --- a/web_src/js/components/DashboardRepoList.vue +++ b/web_src/js/components/DashboardRepoList.vue @@ -130,12 +130,12 @@ export default defineComponent({ }, methods: { - changeTab(t) { - this.tab = t; + changeTab(tab: string) { + this.tab = tab; this.updateHistory(); }, - changeReposFilter(filter) { + changeReposFilter(filter: string) { this.reposFilter = filter; this.repos = []; this.page = 1; @@ -218,7 +218,7 @@ export default defineComponent({ this.searchRepos(); }, - changePage(page) { + changePage(page: number) { this.page = page; if (this.page > this.finalPage) { this.page = this.finalPage; @@ -256,7 +256,7 @@ export default defineComponent({ } if (searchedURL === this.searchURL) { - this.repos = json.data.map((webSearchRepo) => { + this.repos = json.data.map((webSearchRepo: any) => { return { ...webSearchRepo.repository, latest_commit_status_state: webSearchRepo.latest_commit_status?.State, // if latest_commit_status is null, it means there is no commit status @@ -264,7 +264,7 @@ export default defineComponent({ locale_latest_commit_status_state: webSearchRepo.locale_latest_commit_status, }; }); - const count = response.headers.get('X-Total-Count'); + const count = Number(response.headers.get('X-Total-Count')); if (searchedQuery === '' && searchedMode === '' && this.archivedFilter === 'both') { this.reposTotalCount = count; } @@ -275,7 +275,7 @@ export default defineComponent({ } }, - repoIcon(repo) { + repoIcon(repo: any) { if (repo.fork) { return 'octicon-repo-forked'; } else if (repo.mirror) { @@ -298,7 +298,7 @@ export default defineComponent({ return commitStatus[status].color; }, - reposFilterKeyControl(e) { + reposFilterKeyControl(e: KeyboardEvent) { switch (e.key) { case 'Enter': document.querySelector('.repo-owner-name-list li.active a')?.click(); diff --git a/web_src/js/components/DiffCommitSelector.vue b/web_src/js/components/DiffCommitSelector.vue index 840acd4b51..16760d1cb1 100644 --- a/web_src/js/components/DiffCommitSelector.vue +++ b/web_src/js/components/DiffCommitSelector.vue @@ -4,6 +4,22 @@ import {SvgIcon} from '../svg.ts'; import {GET} from '../modules/fetch.ts'; import {generateAriaId} from '../modules/fomantic/base.ts'; +type Commit = { + id: string, + hovered: boolean, + selected: boolean, + summary: string, + committer_or_author_name: string, + time: string, + short_sha: string, +} + +type CommitListResult = { + commits: Array, + last_review_commit_sha: string, + locale: Record, +} + export default defineComponent({ components: {SvgIcon}, data: () => { @@ -16,9 +32,9 @@ export default defineComponent({ locale: { filter_changes_by_commit: el.getAttribute('data-filter_changes_by_commit'), } as Record, - commits: [], + commits: [] as Array, hoverActivated: false, - lastReviewCommitSha: null, + lastReviewCommitSha: '', uniqueIdMenu: generateAriaId(), uniqueIdShowAll: generateAriaId(), }; @@ -71,7 +87,7 @@ export default defineComponent({ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') { const item = document.activeElement; // try to highlight the selected commits const commitIdx = item?.matches('.item') ? item.getAttribute('data-commit-idx') : null; - if (commitIdx) this.highlight(this.commits[commitIdx]); + if (commitIdx) this.highlight(this.commits[Number(commitIdx)]); } }, onKeyUp(event: KeyboardEvent) { @@ -87,7 +103,7 @@ export default defineComponent({ } } }, - highlight(commit) { + highlight(commit: Commit) { if (!this.hoverActivated) return; const indexSelected = this.commits.findIndex((x) => x.selected); const indexCurrentElem = this.commits.findIndex((x) => x.id === commit.id); @@ -125,10 +141,11 @@ export default defineComponent({ } }); }, + /** Load the commits to show in this dropdown */ async fetchCommits() { const resp = await GET(`${this.issueLink}/commits/list`); - const results = await resp.json(); + const results = await resp.json() as CommitListResult; this.commits.push(...results.commits.map((x) => { x.hovered = false; return x; @@ -166,7 +183,7 @@ export default defineComponent({ * the diff from beginning of PR up to the second clicked commit is * opened */ - commitClickedShift(commit) { + commitClickedShift(commit: Commit) { this.hoverActivated = !this.hoverActivated; commit.selected = true; // Second click -> determine our range and open links accordingly diff --git a/web_src/js/components/DiffFileList.vue b/web_src/js/components/DiffFileList.vue index 792a1aefac..6570c92781 100644 --- a/web_src/js/components/DiffFileList.vue +++ b/web_src/js/components/DiffFileList.vue @@ -18,14 +18,14 @@ function toggleFileList() { } function diffTypeToString(pType: number) { - const diffTypes = { - 1: 'add', - 2: 'modify', - 3: 'del', - 4: 'rename', - 5: 'copy', + const diffTypes: Record = { + '1': 'add', + '2': 'modify', + '3': 'del', + '4': 'rename', + '5': 'copy', }; - return diffTypes[pType]; + return diffTypes[String(pType)]; } function diffStatsWidth(adds: number, dels: number) { diff --git a/web_src/js/components/DiffFileTree.vue b/web_src/js/components/DiffFileTree.vue index 8676c4d37f..d00d03565f 100644 --- a/web_src/js/components/DiffFileTree.vue +++ b/web_src/js/components/DiffFileTree.vue @@ -1,5 +1,5 @@