Skip to content

Commit 32075d2

Browse files
authored
Add types to various low-level functions (#31781)
Adds types to various low-level modules. All changes are type-only, no runtime changes. `tsc` now reports 38 less errors. One problem was that `@types/sortablejs` does not accept promise return in its functions which triggered the linter, so I disabled the rules on those line.
1 parent 9633f33 commit 32075d2

File tree

13 files changed

+123
-77
lines changed

13 files changed

+123
-77
lines changed

package-lock.json

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"stylelint-declaration-strict-value": "1.10.6",
108108
"stylelint-value-no-unknown-custom-properties": "6.0.1",
109109
"svgo": "3.3.2",
110+
"type-fest": "4.23.0",
110111
"updates": "16.3.7",
111112
"vite-string-plugin": "1.3.4",
112113
"vitest": "2.0.5"

types.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ declare module '*.svg' {
33
export default value;
44
}
55

6+
declare module '*.css' {
7+
const value: string;
8+
export default value;
9+
}
10+
611
declare let __webpack_public_path__: string;
712

813
interface Window {
@@ -20,3 +25,7 @@ declare module 'htmx.org/dist/htmx.esm.js' {
2025
const value = await import('htmx.org');
2126
export default value;
2227
}
28+
29+
interface Element {
30+
_tippy: import('tippy.js').Instance;
31+
}

web_src/js/features/dropzone.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function addCopyLink(file) {
5252
copyLinkEl.addEventListener('click', async (e) => {
5353
e.preventDefault();
5454
const success = await clippie(generateMarkdownLinkForAttachment(file));
55-
showTemporaryTooltip(e.target, success ? i18n.copy_success : i18n.copy_error);
55+
showTemporaryTooltip(e.target as Element, success ? i18n.copy_success : i18n.copy_error);
5656
});
5757
file.previewTemplate.append(copyLinkEl);
5858
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ async function initIssuePinSort() {
196196

197197
createSortable(pinDiv, {
198198
group: 'shared',
199-
onEnd: pinMoveEnd,
199+
onEnd: pinMoveEnd, // eslint-disable-line @typescript-eslint/no-misused-promises
200200
});
201201
}
202202

web_src/js/features/repo-projects.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async function initRepoProjectSortable() {
6060
handle: '.project-column-header',
6161
delayOnTouchOnly: true,
6262
delay: 500,
63-
onSort: async () => {
63+
onSort: async () => { // eslint-disable-line @typescript-eslint/no-misused-promises
6464
boardColumns = mainBoard.querySelectorAll('.project-column');
6565

6666
const columnSorting = {
@@ -84,8 +84,8 @@ async function initRepoProjectSortable() {
8484
const boardCardList = boardColumn.querySelectorAll('.cards')[0];
8585
createSortable(boardCardList, {
8686
group: 'shared',
87-
onAdd: moveIssue,
88-
onUpdate: moveIssue,
87+
onAdd: moveIssue, // eslint-disable-line @typescript-eslint/no-misused-promises
88+
onUpdate: moveIssue, // eslint-disable-line @typescript-eslint/no-misused-promises
8989
delayOnTouchOnly: true,
9090
delay: 500,
9191
});

web_src/js/features/stopwatch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function initStopwatch() {
2727
stopwatchEl.removeAttribute('href'); // intended for noscript mode only
2828

2929
createTippy(stopwatchEl, {
30-
content: stopwatchPopup.cloneNode(true),
30+
content: stopwatchPopup.cloneNode(true) as Element,
3131
placement: 'bottom-end',
3232
trigger: 'click',
3333
maxWidth: 'none',

web_src/js/modules/dirauto.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {isDocumentFragmentOrElementNode} from '../utils/dom.ts';
22

3+
type DirElement = HTMLInputElement | HTMLTextAreaElement;
4+
35
// for performance considerations, it only uses performant syntax
4-
function attachDirAuto(el) {
6+
function attachDirAuto(el: DirElement) {
57
if (el.type !== 'hidden' &&
68
el.type !== 'checkbox' &&
79
el.type !== 'radio' &&
@@ -18,10 +20,12 @@ export function initDirAuto() {
1820
const mutation = mutationList[i];
1921
const len = mutation.addedNodes.length;
2022
for (let i = 0; i < len; i++) {
21-
const addedNode = mutation.addedNodes[i];
23+
const addedNode = mutation.addedNodes[i] as HTMLElement;
2224
if (!isDocumentFragmentOrElementNode(addedNode)) continue;
23-
if (addedNode.nodeName === 'INPUT' || addedNode.nodeName === 'TEXTAREA') attachDirAuto(addedNode);
24-
const children = addedNode.querySelectorAll('input, textarea');
25+
if (addedNode.nodeName === 'INPUT' || addedNode.nodeName === 'TEXTAREA') {
26+
attachDirAuto(addedNode as DirElement);
27+
}
28+
const children = addedNode.querySelectorAll<DirElement>('input, textarea');
2529
const len = children.length;
2630
for (let childIdx = 0; childIdx < len; childIdx++) {
2731
attachDirAuto(children[childIdx]);
@@ -30,7 +34,7 @@ export function initDirAuto() {
3034
}
3135
});
3236

33-
const docNodes = document.querySelectorAll('input, textarea');
37+
const docNodes = document.querySelectorAll<DirElement>('input, textarea');
3438
const len = docNodes.length;
3539
for (let i = 0; i < len; i++) {
3640
attachDirAuto(docNodes[i]);

web_src/js/modules/sortable.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export async function createSortable(el, opts = {}) {
1+
import type {SortableOptions} from 'sortablejs';
2+
3+
export async function createSortable(el, opts: {handle?: string} & SortableOptions = {}) {
24
const {Sortable} = await import(/* webpackChunkName: "sortablejs" */'sortablejs');
35

46
return new Sortable(el, {
@@ -15,5 +17,5 @@ export async function createSortable(el, opts = {}) {
1517
opts.onUnchoose?.(e);
1618
},
1719
...opts,
18-
});
20+
} satisfies SortableOptions);
1921
}

web_src/js/modules/stores.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {reactive} from 'vue';
2+
import type {Reactive} from 'vue';
23

3-
let diffTreeStoreReactive;
4+
let diffTreeStoreReactive: Reactive<Record<string, any>>;
45
export function diffTreeStore() {
56
if (!diffTreeStoreReactive) {
67
diffTreeStoreReactive = reactive(window.config.pageData.diffFileInfo);

0 commit comments

Comments
 (0)