Skip to content

Commit d8590e1

Browse files
committed
Fix a number of typescript issuest
1 parent 1a07ebe commit d8590e1

16 files changed

+91
-83
lines changed

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

Lines changed: 5 additions & 6 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 23 additions & 21 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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';

web_src/js/features/dropzone.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function createDropzone(el, opts) {
2222
return new Dropzone(el, opts);
2323
}
2424

25-
export function generateMarkdownLinkForAttachment(file, {width, dppx} = {}) {
25+
export function generateMarkdownLinkForAttachment(file, {width, dppx}: {width?: number, dppx?: number} = {}) {
2626
let fileMarkdown = `[${file.name}](/attachments/${file.uuid})`;
2727
if (isImageFile(file)) {
2828
fileMarkdown = `!${fileMarkdown}`;
@@ -60,14 +60,14 @@ function addCopyLink(file) {
6060
/**
6161
* @param {HTMLElement} dropzoneEl
6262
*/
63-
export async function initDropzone(dropzoneEl) {
63+
export async function initDropzone(dropzoneEl: HTMLElement) {
6464
const listAttachmentsUrl = dropzoneEl.closest('[data-attachment-url]')?.getAttribute('data-attachment-url');
6565
const removeAttachmentUrl = dropzoneEl.getAttribute('data-remove-url');
6666
const attachmentBaseLinkUrl = dropzoneEl.getAttribute('data-link-url');
6767

6868
let disableRemovedfileEvent = false; // when resetting the dropzone (removeAllFiles), disable the "removedfile" event
6969
let fileUuidDict = {}; // to record: if a comment has been saved, then the uploaded files won't be deleted from server when clicking the Remove in the dropzone
70-
const opts = {
70+
const opts: Record<string, any> = {
7171
url: dropzoneEl.getAttribute('data-upload-url'),
7272
headers: {'X-Csrf-Token': csrfToken},
7373
acceptedFiles: ['*/*', ''].includes(dropzoneEl.getAttribute('data-accepts')) ? null : dropzoneEl.getAttribute('data-accepts'),

web_src/js/features/emoji.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import emojis from '../../../assets/emoji.json';
1+
import emojis from '../../../assets/emoji.json' with {type: 'json'};
22

33
const {assetUrlPrefix, customEmojis} = window.config;
44

web_src/js/features/eventsource.sharedworker.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ const sourcesByUrl = {};
22
const sourcesByPort = {};
33

44
class Source {
5+
url: string;
6+
eventSource: EventSource;
7+
listening: Record<string, any>;
8+
clients: Array<any>;
9+
510
constructor(url) {
611
this.url = url;
712
this.eventSource = new EventSource(url);
@@ -67,7 +72,7 @@ class Source {
6772
}
6873
}
6974

70-
self.addEventListener('connect', (e) => {
75+
self.addEventListener('connect', (e: Event & {ports: Array<any>}) => {
7176
for (const port of e.ports) {
7277
port.addEventListener('message', (event) => {
7378
if (!self.EventSource) {

web_src/js/features/heatmap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export function initHeatmap() {
2121
// last heatmap tooltip localization attempt https://github.com/go-gitea/gitea/pull/24131/commits/a83761cbbae3c2e3b4bced71e680f44432073ac8
2222
const locale = {
2323
heatMapLocale: {
24-
months: new Array(12).fill().map((_, idx) => translateMonth(idx)),
25-
days: new Array(7).fill().map((_, idx) => translateDay(idx)),
24+
months: new Array(12).fill(undefined).map((_, idx) => translateMonth(idx)),
25+
days: new Array(7).fill(undefined).map((_, idx) => translateDay(idx)),
2626
on: ' - ', // no correct locale support for it, because in many languages the sentence is not "something on someday"
2727
more: el.getAttribute('data-locale-more'),
2828
less: el.getAttribute('data-locale-less'),

web_src/js/features/install.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ function initPreInstall() {
2222
mssql: '127.0.0.1:1433',
2323
};
2424

25-
const dbHost = document.querySelector('#db_host');
26-
const dbUser = document.querySelector('#db_user');
27-
const dbName = document.querySelector('#db_name');
25+
const dbHost = document.querySelector<HTMLInputElement>('#db_host');
26+
const dbUser = document.querySelector<HTMLInputElement>('#db_user');
27+
const dbName = document.querySelector<HTMLInputElement>('#db_name');
2828

2929
// Database type change detection.
3030
document.querySelector('#db_type').addEventListener('change', function () {
@@ -48,56 +48,56 @@ function initPreInstall() {
4848
});
4949
document.querySelector('#db_type').dispatchEvent(new Event('change'));
5050

51-
const appUrl = document.querySelector('#app_url');
51+
const appUrl = document.querySelector<HTMLInputElement>('#app_url');
5252
if (appUrl.value.includes('://localhost')) {
5353
appUrl.value = window.location.href;
5454
}
5555

56-
const domain = document.querySelector('#domain');
56+
const domain = document.querySelector<HTMLInputElement>('#domain');
5757
if (domain.value.trim() === 'localhost') {
5858
domain.value = window.location.hostname;
5959
}
6060

6161
// TODO: better handling of exclusive relations.
6262
document.querySelector('#offline-mode input').addEventListener('change', function () {
6363
if (this.checked) {
64-
document.querySelector('#disable-gravatar input').checked = true;
65-
document.querySelector('#federated-avatar-lookup input').checked = false;
64+
document.querySelector<HTMLInputElement>('#disable-gravatar input').checked = true;
65+
document.querySelector<HTMLInputElement>('#federated-avatar-lookup input').checked = false;
6666
}
6767
});
6868
document.querySelector('#disable-gravatar input').addEventListener('change', function () {
6969
if (this.checked) {
70-
document.querySelector('#federated-avatar-lookup input').checked = false;
70+
document.querySelector<HTMLInputElement>('#federated-avatar-lookup input').checked = false;
7171
} else {
72-
document.querySelector('#offline-mode input').checked = false;
72+
document.querySelector<HTMLInputElement>('#offline-mode input').checked = false;
7373
}
7474
});
7575
document.querySelector('#federated-avatar-lookup input').addEventListener('change', function () {
7676
if (this.checked) {
77-
document.querySelector('#disable-gravatar input').checked = false;
78-
document.querySelector('#offline-mode input').checked = false;
77+
document.querySelector<HTMLInputElement>('#disable-gravatar input').checked = false;
78+
document.querySelector<HTMLInputElement>('#offline-mode input').checked = false;
7979
}
8080
});
8181
document.querySelector('#enable-openid-signin input').addEventListener('change', function () {
8282
if (this.checked) {
83-
if (!document.querySelector('#disable-registration input').checked) {
84-
document.querySelector('#enable-openid-signup input').checked = true;
83+
if (!document.querySelector<HTMLInputElement>('#disable-registration input').checked) {
84+
document.querySelector<HTMLInputElement>('#enable-openid-signup input').checked = true;
8585
}
8686
} else {
87-
document.querySelector('#enable-openid-signup input').checked = false;
87+
document.querySelector<HTMLInputElement>('#enable-openid-signup input').checked = false;
8888
}
8989
});
9090
document.querySelector('#disable-registration input').addEventListener('change', function () {
9191
if (this.checked) {
92-
document.querySelector('#enable-captcha input').checked = false;
93-
document.querySelector('#enable-openid-signup input').checked = false;
92+
document.querySelector<HTMLInputElement>('#enable-captcha input').checked = false;
93+
document.querySelector<HTMLInputElement>('#enable-openid-signup input').checked = false;
9494
} else {
95-
document.querySelector('#enable-openid-signup input').checked = true;
95+
document.querySelector<HTMLInputElement>('#enable-openid-signup input').checked = true;
9696
}
9797
});
9898
document.querySelector('#enable-captcha input').addEventListener('change', function () {
9999
if (this.checked) {
100-
document.querySelector('#disable-registration input').checked = false;
100+
document.querySelector<HTMLInputElement>('#disable-registration input').checked = false;
101101
}
102102
});
103103
}

0 commit comments

Comments
 (0)