Skip to content

Commit c8ea41b

Browse files
Fix remaining typescript issues, enable tsc (#32840)
Fixes 79 typescript errors. Discovered at least two bugs in `notifications.ts`, and I'm pretty sure this feature was at least partially broken and may still be, I don't really know how to test it. After this, only like ~10 typescript errors remain in the codebase but those are harder to solve. --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent 74b06d4 commit c8ea41b

24 files changed

+152
-134
lines changed

Makefile

+2-6
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,12 @@ lint-backend-fix: lint-go-fix lint-go-vet lint-editorconfig
377377
.PHONY: lint-js
378378
lint-js: node_modules
379379
npx eslint --color --max-warnings=0 --ext js,ts,vue $(ESLINT_FILES)
380-
# npx vue-tsc
380+
npx vue-tsc
381381

382382
.PHONY: lint-js-fix
383383
lint-js-fix: node_modules
384384
npx eslint --color --max-warnings=0 --ext js,ts,vue $(ESLINT_FILES) --fix
385-
# npx vue-tsc
385+
npx vue-tsc
386386

387387
.PHONY: lint-css
388388
lint-css: node_modules
@@ -451,10 +451,6 @@ lint-templates: .venv node_modules
451451
lint-yaml: .venv
452452
@poetry run yamllint .
453453

454-
.PHONY: tsc
455-
tsc:
456-
npx vue-tsc
457-
458454
.PHONY: watch
459455
watch:
460456
@bash tools/watch.sh

package-lock.json

+31-31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"devDependencies": {
6767
"@eslint-community/eslint-plugin-eslint-comments": "4.4.1",
6868
"@playwright/test": "1.49.0",
69+
"@silverwind/vue-tsc": "2.1.13",
6970
"@stoplight/spectral-cli": "6.14.2",
7071
"@stylistic/eslint-plugin-js": "2.11.0",
7172
"@stylistic/stylelint-plugin": "3.1.1",
@@ -110,8 +111,7 @@
110111
"type-fest": "4.30.0",
111112
"updates": "16.4.0",
112113
"vite-string-plugin": "1.3.4",
113-
"vitest": "2.1.8",
114-
"vue-tsc": "2.1.10"
114+
"vitest": "2.1.8"
115115
},
116116
"browserslist": [
117117
"defaults"

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
],
88
"compilerOptions": {
99
"target": "es2020",
10-
"module": "nodenext",
10+
"module": "esnext",
11+
"moduleResolution": "bundler",
1112
"lib": ["dom", "dom.iterable", "dom.asynciterable", "esnext"],
1213
"allowImportingTsExtensions": true,
1314
"allowJs": true,

web_src/js/features/common-issue-list.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@ const reIssueSharpIndex = /^#(\d+)$/; // eg: "#123"
77
const reIssueOwnerRepoIndex = /^([-.\w]+)\/([-.\w]+)#(\d+)$/; // eg: "{owner}/{repo}#{index}"
88

99
// if the searchText can be parsed to an "issue goto link", return the link, otherwise return empty string
10-
export function parseIssueListQuickGotoLink(repoLink, searchText) {
10+
export function parseIssueListQuickGotoLink(repoLink: string, searchText: string) {
1111
searchText = searchText.trim();
1212
let targetUrl = '';
1313
if (repoLink) {
1414
// try to parse it in current repo
1515
if (reIssueIndex.test(searchText)) {
1616
targetUrl = `${repoLink}/issues/${searchText}`;
1717
} else if (reIssueSharpIndex.test(searchText)) {
18-
targetUrl = `${repoLink}/issues/${searchText.substr(1)}`;
18+
targetUrl = `${repoLink}/issues/${searchText.substring(1)}`;
1919
}
2020
} else {
2121
// try to parse it for a global search (eg: "owner/repo#123")
22-
const matchIssueOwnerRepoIndex = searchText.match(reIssueOwnerRepoIndex);
23-
if (matchIssueOwnerRepoIndex) {
24-
const [_, owner, repo, index] = matchIssueOwnerRepoIndex;
22+
const [_, owner, repo, index] = reIssueOwnerRepoIndex.exec(searchText) || [];
23+
if (owner) {
2524
targetUrl = `${appSubUrl}/${owner}/${repo}/issues/${index}`;
2625
}
2726
}
@@ -33,7 +32,7 @@ export function initCommonIssueListQuickGoto() {
3332
if (!goto) return;
3433

3534
const form = goto.closest('form');
36-
const input = form.querySelector('input[name=q]');
35+
const input = form.querySelector<HTMLInputElement>('input[name=q]');
3736
const repoLink = goto.getAttribute('data-repo-link');
3837

3938
form.addEventListener('submit', (e) => {

web_src/js/features/comp/ComboMarkdownEditor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ export class ComboMarkdownEditor {
283283
];
284284
}
285285

286-
parseEasyMDEToolbar(EasyMDE, actions) {
287-
this.easyMDEToolbarActions = this.easyMDEToolbarActions || easyMDEToolbarActions(EasyMDE, this);
286+
parseEasyMDEToolbar(easyMde: typeof EasyMDE, actions) {
287+
this.easyMDEToolbarActions = this.easyMDEToolbarActions || easyMDEToolbarActions(easyMde, this);
288288
const processed = [];
289289
for (const action of actions) {
290290
const actionButton = this.easyMDEToolbarActions[action];

web_src/js/features/comp/EasyMDEToolbarActions.ts

+23-21
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,102 @@
11
import {svg} from '../../svg.ts';
2+
import type EasyMDE from 'easymde';
3+
import type {ComboMarkdownEditor} from './ComboMarkdownEditor.ts';
24

3-
export function easyMDEToolbarActions(EasyMDE, editor) {
4-
const actions = {
5+
export function easyMDEToolbarActions(easyMde: typeof EasyMDE, editor: ComboMarkdownEditor): Record<string, Partial<EasyMDE.ToolbarIcon | string>> {
6+
const actions: Record<string, Partial<EasyMDE.ToolbarIcon> | string> = {
57
'|': '|',
68
'heading-1': {
7-
action: EasyMDE.toggleHeading1,
9+
action: easyMde.toggleHeading1,
810
icon: svg('octicon-heading'),
911
title: 'Heading 1',
1012
},
1113
'heading-2': {
12-
action: EasyMDE.toggleHeading2,
14+
action: easyMde.toggleHeading2,
1315
icon: svg('octicon-heading'),
1416
title: 'Heading 2',
1517
},
1618
'heading-3': {
17-
action: EasyMDE.toggleHeading3,
19+
action: easyMde.toggleHeading3,
1820
icon: svg('octicon-heading'),
1921
title: 'Heading 3',
2022
},
2123
'heading-smaller': {
22-
action: EasyMDE.toggleHeadingSmaller,
24+
action: easyMde.toggleHeadingSmaller,
2325
icon: svg('octicon-heading'),
2426
title: 'Decrease Heading',
2527
},
2628
'heading-bigger': {
27-
action: EasyMDE.toggleHeadingBigger,
29+
action: easyMde.toggleHeadingBigger,
2830
icon: svg('octicon-heading'),
2931
title: 'Increase Heading',
3032
},
3133
'bold': {
32-
action: EasyMDE.toggleBold,
34+
action: easyMde.toggleBold,
3335
icon: svg('octicon-bold'),
3436
title: 'Bold',
3537
},
3638
'italic': {
37-
action: EasyMDE.toggleItalic,
39+
action: easyMde.toggleItalic,
3840
icon: svg('octicon-italic'),
3941
title: 'Italic',
4042
},
4143
'strikethrough': {
42-
action: EasyMDE.toggleStrikethrough,
44+
action: easyMde.toggleStrikethrough,
4345
icon: svg('octicon-strikethrough'),
4446
title: 'Strikethrough',
4547
},
4648
'quote': {
47-
action: EasyMDE.toggleBlockquote,
49+
action: easyMde.toggleBlockquote,
4850
icon: svg('octicon-quote'),
4951
title: 'Quote',
5052
},
5153
'code': {
52-
action: EasyMDE.toggleCodeBlock,
54+
action: easyMde.toggleCodeBlock,
5355
icon: svg('octicon-code'),
5456
title: 'Code',
5557
},
5658
'link': {
57-
action: EasyMDE.drawLink,
59+
action: easyMde.drawLink,
5860
icon: svg('octicon-link'),
5961
title: 'Link',
6062
},
6163
'unordered-list': {
62-
action: EasyMDE.toggleUnorderedList,
64+
action: easyMde.toggleUnorderedList,
6365
icon: svg('octicon-list-unordered'),
6466
title: 'Unordered List',
6567
},
6668
'ordered-list': {
67-
action: EasyMDE.toggleOrderedList,
69+
action: easyMde.toggleOrderedList,
6870
icon: svg('octicon-list-ordered'),
6971
title: 'Ordered List',
7072
},
7173
'image': {
72-
action: EasyMDE.drawImage,
74+
action: easyMde.drawImage,
7375
icon: svg('octicon-image'),
7476
title: 'Image',
7577
},
7678
'table': {
77-
action: EasyMDE.drawTable,
79+
action: easyMde.drawTable,
7880
icon: svg('octicon-table'),
7981
title: 'Table',
8082
},
8183
'horizontal-rule': {
82-
action: EasyMDE.drawHorizontalRule,
84+
action: easyMde.drawHorizontalRule,
8385
icon: svg('octicon-horizontal-rule'),
8486
title: 'Horizontal Rule',
8587
},
8688
'preview': {
87-
action: EasyMDE.togglePreview,
89+
action: easyMde.togglePreview,
8890
icon: svg('octicon-eye'),
8991
title: 'Preview',
9092
},
9193
'fullscreen': {
92-
action: EasyMDE.toggleFullScreen,
94+
action: easyMde.toggleFullScreen,
9395
icon: svg('octicon-screen-full'),
9496
title: 'Fullscreen',
9597
},
9698
'side-by-side': {
97-
action: EasyMDE.toggleSideBySide,
99+
action: easyMde.toggleSideBySide,
98100
icon: svg('octicon-columns'),
99101
title: 'Side by Side',
100102
},

web_src/js/features/comp/ReactionSelector.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {fomanticQuery} from '../../modules/fomantic/base.ts';
33

44
export function initCompReactionSelector(parent: ParentNode = document) {
55
for (const container of parent.querySelectorAll('.issue-content, .diff-file-body')) {
6-
container.addEventListener('click', async (e) => {
6+
container.addEventListener('click', async (e: MouseEvent & {target: HTMLElement}) => {
77
// there are 2 places for the "reaction" buttons, one is the top-right reaction menu, one is the bottom of the comment
88
const target = e.target.closest('.comment-reaction-button');
99
if (!target) return;

web_src/js/features/comp/WebHookEditor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function initCompWebHookEditor() {
2323
}
2424

2525
// some webhooks (like Gitea) allow to set the request method (GET/POST), and it would toggle the "Content Type" field
26-
const httpMethodInput = document.querySelector('#http_method');
26+
const httpMethodInput = document.querySelector<HTMLInputElement>('#http_method');
2727
if (httpMethodInput) {
2828
const updateContentType = function () {
2929
const visible = httpMethodInput.value === 'POST';

0 commit comments

Comments
 (0)