Skip to content

Commit 8ffc678

Browse files
Copilotsilverwindwxiaoguang
authored andcommitted
Remove and forbid @ts-expect-error (#36513)
Removes `@ts-expect-error` in the code base and forbids it. --------- Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: silverwind <115237+silverwind@users.noreply.github.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent 1d781c8 commit 8ffc678

22 files changed

+418
-291
lines changed

eslint.config.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import vue from 'eslint-plugin-vue';
1515
import vueScopedCss from 'eslint-plugin-vue-scoped-css';
1616
import wc from 'eslint-plugin-wc';
1717
import {defineConfig, globalIgnores} from 'eslint/config';
18+
import type {ESLint} from 'eslint';
1819

1920
const jsExts = ['js', 'mjs', 'cjs'] as const;
2021
const tsExts = ['ts', 'mts', 'cts'] as const;
@@ -62,8 +63,7 @@ export default defineConfig([
6263
'@stylistic': stylistic,
6364
'@typescript-eslint': typescriptPlugin.plugin,
6465
'array-func': arrayFunc,
65-
// @ts-expect-error -- https://github.com/un-ts/eslint-plugin-import-x/issues/203
66-
'import-x': importPlugin,
66+
'import-x': importPlugin as unknown as ESLint.Plugin, // https://github.com/un-ts/eslint-plugin-import-x/issues/203
6767
regexp,
6868
sonarjs,
6969
unicorn,
@@ -156,7 +156,7 @@ export default defineConfig([
156156
'@typescript-eslint/adjacent-overload-signatures': [0],
157157
'@typescript-eslint/array-type': [0],
158158
'@typescript-eslint/await-thenable': [2],
159-
'@typescript-eslint/ban-ts-comment': [2, {'ts-expect-error': false, 'ts-ignore': true, 'ts-nocheck': false, 'ts-check': false}],
159+
'@typescript-eslint/ban-ts-comment': [2, {'ts-expect-error': true, 'ts-ignore': true, 'ts-nocheck': false, 'ts-check': false}],
160160
'@typescript-eslint/ban-tslint-comment': [0],
161161
'@typescript-eslint/class-literal-property-style': [0],
162162
'@typescript-eslint/class-methods-use-this': [0],
@@ -924,8 +924,7 @@ export default defineConfig([
924924
},
925925
extends: [
926926
vue.configs['flat/recommended'],
927-
// @ts-expect-error
928-
vueScopedCss.configs['flat/recommended'],
927+
vueScopedCss.configs['flat/recommended'] as any,
929928
],
930929
rules: {
931930
'vue/attributes-order': [0],

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"target": "es2020",
1414
"module": "esnext",
1515
"moduleResolution": "bundler",
16-
"lib": ["dom", "dom.iterable", "dom.asynciterable", "esnext"],
16+
"lib": ["dom", "dom.iterable", "dom.asynciterable", "esnext", "webworker"],
1717
"allowImportingTsExtensions": true,
1818
"allowJs": true,
1919
"allowSyntheticDefaultImports": true,

types.d.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,105 @@ declare module '@techknowlogick/license-checker-webpack-plugin' {
22
const plugin: any;
33
export = plugin;
44
}
5+
56
declare module 'eslint-plugin-no-use-extend-native' {
67
import type {Eslint} from 'eslint';
78
const plugin: Eslint.Plugin;
89
export = plugin;
910
}
11+
1012
declare module 'eslint-plugin-array-func' {
1113
import type {Eslint} from 'eslint';
1214
const plugin: Eslint.Plugin;
1315
export = plugin;
1416
}
17+
1518
declare module 'eslint-plugin-github' {
1619
import type {Eslint} from 'eslint';
1720
const plugin: Eslint.Plugin;
1821
export = plugin;
1922
}
23+
24+
declare module '*.svg' {
25+
const value: string;
26+
export default value;
27+
}
28+
29+
declare module '*.css' {
30+
const value: string;
31+
export default value;
32+
}
33+
34+
declare module '*.vue' {
35+
import type {DefineComponent} from 'vue';
36+
const component: DefineComponent<unknown, unknown, any>;
37+
export default component;
38+
// Here we declare all exports from vue files so `tsc` or `tsgo` can work for
39+
// non-vue files. To lint .vue files, `vue-tsc` must be used.
40+
export function initDashboardRepoList(): void;
41+
export function initRepositoryActionView(): void;
42+
}
43+
44+
declare module 'htmx.org/dist/htmx.esm.js' {
45+
const value = await import('htmx.org');
46+
export default value;
47+
}
48+
49+
declare module 'swagger-ui-dist/swagger-ui-es-bundle.js' {
50+
const value = await import('swagger-ui-dist');
51+
export default value.SwaggerUIBundle;
52+
}
53+
54+
declare module 'asciinema-player' {
55+
interface AsciinemaPlayer {
56+
create(src: string, element: HTMLElement, options?: Record<string, unknown>): void;
57+
}
58+
const exports: AsciinemaPlayer;
59+
export = exports;
60+
}
61+
62+
declare module '@citation-js/core' {
63+
export class Cite {
64+
constructor(data: string);
65+
format(format: string, options?: Record<string, any>): string;
66+
}
67+
export const plugins: {
68+
config: {
69+
get(name: string): any;
70+
};
71+
};
72+
}
73+
74+
declare module '@citation-js/plugin-software-formats' {}
75+
declare module '@citation-js/plugin-bibtex' {}
76+
declare module '@citation-js/plugin-csl' {}
77+
78+
declare module 'vue-bar-graph' {
79+
import type {DefineComponent} from 'vue';
80+
81+
interface BarGraphPoint {
82+
value: number;
83+
label: string;
84+
}
85+
86+
export const VueBarGraph: DefineComponent<{
87+
points?: Array<BarGraphPoint>;
88+
barColor?: string;
89+
textColor?: string;
90+
textAltColor?: string;
91+
height?: number;
92+
labelHeight?: number;
93+
}>;
94+
}
95+
96+
declare module '@mcaptcha/vanilla-glue' {
97+
export let INPUT_NAME: string;
98+
export default class Widget {
99+
constructor(options: {
100+
siteKey: {
101+
instanceUrl: URL;
102+
key: string;
103+
};
104+
});
105+
}
106+
}

web_src/js/bootstrap.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,12 @@ function initGlobalErrorHandler() {
8080
// we added an event handler for window error at the very beginning of <script> of page head the
8181
// handler calls `_globalHandlerErrors.push` (array method) to record all errors occur before
8282
// this init then in this init, we can collect all error events and show them.
83-
for (const e of window._globalHandlerErrors || []) {
83+
for (const e of (window._globalHandlerErrors as Iterable<ErrorEvent & PromiseRejectionEvent>) || []) {
8484
processWindowErrorEvent(e);
8585
}
8686
// then, change _globalHandlerErrors to an object with push method, to process further error
8787
// events directly
88-
// @ts-expect-error -- this should be refactored to not use a fake array
89-
window._globalHandlerErrors = {_inited: true, push: (e: ErrorEvent & PromiseRejectionEvent) => processWindowErrorEvent(e)};
88+
window._globalHandlerErrors = {_inited: true, push: (e: ErrorEvent & PromiseRejectionEvent) => processWindowErrorEvent(e)} as any;
9089
}
9190

9291
initGlobalErrorHandler();

web_src/js/components/RepoActionView.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {localUserSettings} from '../modules/user-settings.ts';
1313
// see "models/actions/status.go", if it needs to be used somewhere else, move it to a shared file like "types/actions.ts"
1414
type RunStatus = 'unknown' | 'waiting' | 'running' | 'success' | 'failure' | 'cancelled' | 'skipped' | 'blocked';
1515
16+
type StepContainerElement = HTMLElement & {_stepLogsActiveContainer?: HTMLElement}
17+
1618
type LogLine = {
1719
index: number;
1820
timestamp: number;
@@ -221,19 +223,18 @@ export default defineComponent({
221223
},
222224
223225
// get the job step logs container ('.job-step-logs')
224-
getJobStepLogsContainer(stepIndex: number): HTMLElement {
226+
getJobStepLogsContainer(stepIndex: number): StepContainerElement {
225227
return (this.$refs.logs as any)[stepIndex];
226228
},
227229
228230
// get the active logs container element, either the `job-step-logs` or the `job-log-list` in the `job-log-group`
229-
getActiveLogsContainer(stepIndex: number): HTMLElement {
231+
getActiveLogsContainer(stepIndex: number): StepContainerElement {
230232
const el = this.getJobStepLogsContainer(stepIndex);
231-
// @ts-expect-error - _stepLogsActiveContainer is a custom property
232233
return el._stepLogsActiveContainer ?? el;
233234
},
234235
// begin a log group
235236
beginLogGroup(stepIndex: number, startTime: number, line: LogLine, cmd: LogLineCommand) {
236-
const el = (this.$refs.logs as any)[stepIndex];
237+
const el = (this.$refs.logs as any)[stepIndex] as StepContainerElement;
237238
const elJobLogGroupSummary = createElementFromAttrs('summary', {class: 'job-log-group-summary'},
238239
this.createLogLine(stepIndex, startTime, {
239240
index: line.index,
@@ -395,7 +396,7 @@ export default defineComponent({
395396
}
396397
397398
// auto-scroll to the last log line of the last step
398-
let autoScrollJobStepElement: HTMLElement | undefined;
399+
let autoScrollJobStepElement: StepContainerElement | undefined;
399400
for (let stepIndex = 0; stepIndex < this.currentJob.steps.length; stepIndex++) {
400401
if (!autoScrollStepIndexes.get(stepIndex)) continue;
401402
autoScrollJobStepElement = this.getJobStepLogsContainer(stepIndex);

web_src/js/components/RepoActivityTopAuthors.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script lang="ts" setup>
2-
// @ts-expect-error - module exports no types
32
import {VueBarGraph} from 'vue-bar-graph';
43
import {computed, onMounted, shallowRef, useTemplateRef, type ShallowRef} from 'vue';
54

web_src/js/components/RepoBranchTagSelector.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,8 @@ export default defineComponent({
155155
return -1;
156156
},
157157
getActiveItem() {
158-
const el = this.$refs[`listItem${this.activeItemIndex}`];
159-
// @ts-expect-error - el is unknown type
160-
return (el && el.length) ? el[0] : null;
158+
const el = this.$refs[`listItem${this.activeItemIndex}`] as Array<HTMLDivElement>;
159+
return el?.length ? el[0] : null;
161160
},
162161
keydown(e: KeyboardEvent) {
163162
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
@@ -174,7 +173,7 @@ export default defineComponent({
174173
return;
175174
}
176175
this.activeItemIndex = nextIndex;
177-
this.getActiveItem().scrollIntoView({block: 'nearest'});
176+
this.getActiveItem()!.scrollIntoView({block: 'nearest'});
178177
} else if (e.key === 'Enter') {
179178
e.preventDefault();
180179
this.getActiveItem()?.click();

web_src/js/components/RepoContributors.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ const customEventListener: Plugin = {
4141
},
4242
};
4343
44+
type LineOptions = ChartOptions<'line'> & {
45+
plugins?: {
46+
customEventListener?: {
47+
chartType: string;
48+
instance: unknown;
49+
};
50+
};
51+
}
52+
4453
Chart.defaults.color = chartJsColors.text;
4554
Chart.defaults.borderColor = chartJsColors.border;
4655
@@ -251,7 +260,7 @@ export default defineComponent({
251260
}
252261
},
253262
254-
getOptions(type: string): ChartOptions<'line'> {
263+
getOptions(type: string): LineOptions {
255264
return {
256265
responsive: true,
257266
maintainAspectRatio: false,
@@ -264,7 +273,6 @@ export default defineComponent({
264273
position: 'top',
265274
align: 'center',
266275
},
267-
// @ts-expect-error: bug in chart.js types
268276
customEventListener: {
269277
chartType: type,
270278
instance: this,

web_src/js/components/RepoRecentCommits.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
TimeScale,
99
type ChartOptions,
1010
type ChartData,
11+
type ChartDataset,
1112
} from 'chart.js';
1213
import {GET} from '../modules/fetch.ts';
1314
import {Bar} from 'vue-chartjs';
@@ -83,13 +84,12 @@ function toGraphData(data: DayData[]): ChartData<'bar'> {
8384
return {
8485
datasets: [
8586
{
86-
// @ts-expect-error -- bar chart expects one-dimensional data, but apparently x/y still works
8787
data: data.map((i) => ({x: i.week, y: i.commits})),
8888
label: 'Commits',
8989
backgroundColor: chartJsColors['commits'],
9090
borderWidth: 0,
9191
tension: 0.3,
92-
},
92+
} as unknown as ChartDataset<'bar'>,
9393
],
9494
};
9595
}

web_src/js/features/captcha.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export async function initCaptcha() {
4141
// * the INPUT_NAME is a "const", it should not be changed.
4242
// * the "mCaptcha.default" is actually the "Widget".
4343

44-
// @ts-expect-error TS2540: Cannot assign to 'INPUT_NAME' because it is a read-only property.
4544
mCaptcha.INPUT_NAME = 'm-captcha-response';
4645
const instanceURL = captchaEl.getAttribute('data-instance-url')!;
4746

0 commit comments

Comments
 (0)