소스 검색

更优雅的类型声明

Michael Wang 3 년 전
부모
커밋
d236061a9b
1개의 변경된 파일3개의 추가작업 그리고 6개의 파일을 삭제
  1. 3 6
      src/features/OnlineExam/CheckComputer.vue

+ 3 - 6
src/features/OnlineExam/CheckComputer.vue

@@ -30,7 +30,7 @@ const network = $ref({
 const time = $ref({
   currentTimeZone: moment().format("Z"),
   timeZoneStatus: new Date().getTimezoneOffset() / 60 === -8,
-  clockRateDiff: null,
+  clockRateDiff: null as unknown as number | null,
   clockRateStateResolved: false,
   clockRateStatus: false,
 });
@@ -54,8 +54,8 @@ const wechat = $ref({
   qrScanned: false,
   uploadResolved: false,
   uploadStatus: false,
-  studentAnswer: null,
-  examRecordDataId: null,
+  studentAnswer: null as unknown as string | null,
+  examRecordDataId: null as unknown as string | null,
 });
 
 const step1Status = $computed(() => {
@@ -101,7 +101,6 @@ addTimeout(() => {
     if (isUnmounted) return;
     end = moment(e.headers.get("date"));
     time.clockRateStateResolved = true;
-    // @ts-expect-error 不方便给clockRateDiff定义 number | null
     time.clockRateDiff = end.diff(start, "seconds") - CLOCK_RATE_TIMEOUT;
     time.clockRateStatus = end.diff(start, "seconds") < CLOCK_RATE_TIMEOUT + 2;
   });
@@ -130,7 +129,6 @@ onMounted(async () => {
   const trueExamRecordDataId = decodeURIComponent(wechat.qrValue).match(
     /&examRecordDataId=(\d+)/
   )![1];
-  // @ts-expect-error
   wechat.examRecordDataId = trueExamRecordDataId;
 });
 // websocket 会在unmounted时自动关闭
@@ -161,7 +159,6 @@ watch(
             }
           )
           .then(() => {
-            // @ts-expect-error
             wechat.studentAnswer = q.fileUrl;
             wechat.uploadResolved = true;
             wechat.uploadStatus = true;