Skip to content

Commit 2352ba9

Browse files
committed
more type improvements
1 parent a3ffc77 commit 2352ba9

File tree

8 files changed

+27
-25
lines changed

8 files changed

+27
-25
lines changed

web_src/js/components/DiffFileList.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function toggleFileList() {
1717
store.fileListIsVisible = !store.fileListIsVisible;
1818
}
1919
20-
function diffTypeToString(pType) {
20+
function diffTypeToString(pType: number) {
2121
const diffTypes = {
2222
1: 'add',
2323
2: 'modify',
@@ -28,7 +28,7 @@ function diffTypeToString(pType) {
2828
return diffTypes[pType];
2929
}
3030
31-
function diffStatsWidth(adds, dels) {
31+
function diffStatsWidth(adds: number, dels: number) {
3232
return `${adds / (adds + dels) * 100}%`;
3333
}
3434

web_src/js/components/DiffFileTree.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const fileTree = computed(() => {
6060
parent = newParent;
6161
}
6262
}
63-
const mergeChildIfOnlyOneDir = (entries) => {
63+
const mergeChildIfOnlyOneDir = (entries: Array<Record<string, any>>) => {
6464
for (const entry of entries) {
6565
if (entry.children) {
6666
mergeChildIfOnlyOneDir(entry.children);
@@ -110,13 +110,13 @@ function toggleVisibility() {
110110
updateVisibility(!store.fileTreeIsVisible);
111111
}
112112
113-
function updateVisibility(visible) {
113+
function updateVisibility(visible: boolean) {
114114
store.fileTreeIsVisible = visible;
115115
localStorage.setItem(LOCAL_STORAGE_KEY, store.fileTreeIsVisible);
116116
updateState(store.fileTreeIsVisible);
117117
}
118118
119-
function updateState(visible) {
119+
function updateState(visible: boolean) {
120120
const btn = document.querySelector('.diff-toggle-file-tree-button');
121121
const [toShow, toHide] = btn.querySelectorAll('.icon');
122122
const tree = document.querySelector('#diff-file-tree');

web_src/js/components/DiffFileTreeItem.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defineProps<{
2525
const store = diffTreeStore();
2626
const collapsed = ref(false);
2727
28-
function getIconForDiffType(pType) {
28+
function getIconForDiffType(pType: number) {
2929
const diffTypes = {
3030
1: {name: 'octicon-diff-added', classes: ['text', 'green']},
3131
2: {name: 'octicon-diff-modified', classes: ['text', 'yellow']},
@@ -36,7 +36,7 @@ function getIconForDiffType(pType) {
3636
return diffTypes[pType];
3737
}
3838
39-
function fileIcon(file) {
39+
function fileIcon(file: File) {
4040
if (file.IsSubmodule) {
4141
return 'octicon-file-submodule';
4242
}

web_src/js/components/PullRequestMergeForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function toggleActionForm(show: boolean) {
6868
mergeMessageFieldValue.value = mergeStyleDetail.value.mergeMessageFieldText;
6969
}
7070
71-
function switchMergeStyle(name, autoMerge = false) {
71+
function switchMergeStyle(name: string, autoMerge = false) {
7272
mergeStyle.value = name;
7373
autoMergeWhenSucceed.value = autoMerge;
7474
}

web_src/js/components/RepoActionView.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import {SvgIcon} from '../svg.ts';
33
import ActionRunStatus from './ActionRunStatus.vue';
4-
import {defineComponent} from 'vue';
4+
import {defineComponent, type PropType} from 'vue';
55
import {createElementFromAttrs, toggleElem} from '../utils/dom.ts';
66
import {formatDatetime} from '../utils/time.ts';
77
import {renderAnsi} from '../render/ansi.ts';
@@ -77,7 +77,7 @@ export default defineComponent({
7777
default: '',
7878
},
7979
locale: {
80-
type: Object,
80+
type: Object as PropType<Record<string, string>>,
8181
default: null,
8282
},
8383
},

web_src/js/components/RepoActivityTopAuthors.vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ const colors = ref({
88
textAltColor: 'white',
99
});
1010
11-
// possible keys:
12-
// * avatar_link: (...)
13-
// * commits: (...)
14-
// * home_link: (...)
15-
// * login: (...)
16-
// * name: (...)
17-
const activityTopAuthors = window.config.pageData.repoActivityTopAuthors || [];
11+
type ActivityAuthorData = {
12+
avatar_link: string;
13+
commits: number;
14+
home_link: string;
15+
login: string;
16+
name: string;
17+
}
18+
19+
const activityTopAuthors: Array<ActivityAuthorData> = window.config.pageData.repoActivityTopAuthors || [];
1820
1921
const graphPoints = computed(() => {
2022
return activityTopAuthors.map((item) => {
@@ -26,7 +28,7 @@ const graphPoints = computed(() => {
2628
});
2729
2830
const graphAuthors = computed(() => {
29-
return activityTopAuthors.map((item, idx) => {
31+
return activityTopAuthors.map((item, idx: number) => {
3032
return {
3133
position: idx + 1,
3234
...item,

web_src/js/components/RepoContributors.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import {defineComponent} from 'vue';
2+
import {defineComponent, type PropType} from 'vue';
33
import {SvgIcon} from '../svg.ts';
44
import dayjs from 'dayjs';
55
import {
@@ -61,7 +61,7 @@ export default defineComponent({
6161
components: {ChartLine, SvgIcon},
6262
props: {
6363
locale: {
64-
type: Object,
64+
type: Object as PropType<Record<string, any>>,
6565
required: true,
6666
},
6767
repoLink: {
@@ -89,7 +89,7 @@ export default defineComponent({
8989
this.fetchGraphData();
9090
9191
fomanticQuery('#repo-contributors').dropdown({
92-
onChange: (val) => {
92+
onChange: (val: string) => {
9393
this.xAxisMin = this.xAxisStart;
9494
this.xAxisMax = this.xAxisEnd;
9595
this.type = val;

web_src/js/svg.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {defineComponent, h} from 'vue';
1+
import {defineComponent, h, type PropType} from 'vue';
22
import {parseDom, serializeXml} from './utils.ts';
33
import giteaDoubleChevronLeft from '../../public/assets/img/svg/gitea-double-chevron-left.svg';
44
import giteaDoubleChevronRight from '../../public/assets/img/svg/gitea-double-chevron-right.svg';
@@ -197,13 +197,13 @@ export function svgParseOuterInner(name: SvgName) {
197197
export const SvgIcon = defineComponent({
198198
name: 'SvgIcon',
199199
props: {
200-
name: {type: String, required: true},
200+
name: {type: String as PropType<SvgName>, required: true},
201201
size: {type: Number, default: 16},
202202
className: {type: String, default: ''},
203203
symbolId: {type: String},
204204
},
205205
render() {
206-
let {svgOuter, svgInnerHtml} = svgParseOuterInner(this.name as SvgName);
206+
let {svgOuter, svgInnerHtml} = svgParseOuterInner(this.name);
207207
// https://vuejs.org/guide/extras/render-function.html#creating-vnodes
208208
// the `^` is used for attr, set SVG attributes like 'width', `aria-hidden`, `viewBox`, etc
209209
const attrs = {};
@@ -215,7 +215,7 @@ export const SvgIcon = defineComponent({
215215
attrs[`^height`] = this.size;
216216

217217
// make the <SvgIcon class="foo" class-name="bar"> classes work together
218-
const classes = [];
218+
const classes: Array<string> = [];
219219
for (const cls of svgOuter.classList) {
220220
classes.push(cls);
221221
}

0 commit comments

Comments
 (0)