fix using any type

This commit is contained in:
Chen, Tai-Lin committed 2024-03-04 23:38:18 +08:00
1 parent ddaefca5fb
commit ec63bba0fe
5 files changed
+48 -17

No files matched your search

+7 -1
View File
@@ -3,8 +3,14 @@ import { computed } from 'vue'
import MarkdownText from './MarkdownText.vue' import MarkdownText from './MarkdownText.vue'
import sessionStore from '../store/session' import sessionStore from '../store/session'
interface Task {
id: number
name: string
completed: boolean
}
const tasks = computed(() => { const tasks = computed(() => {
return sessionStore.session.tasks.map((task: any) => { return sessionStore.session.tasks.map((task: Task) => {
const prefix = task.completed ? '✓' : '➤' const prefix = task.completed ? '✓' : '➤'
const color = task.completed ? 'text-text-primary' : 'text-text' const color = task.completed ? 'text-text-primary' : 'text-text'
return { return {
+2 -2
View File
@@ -5,7 +5,7 @@ import TreeChart from './TreeChart.vue'
const treeRef = ref<HTMLElement | null>(null) const treeRef = ref<HTMLElement | null>(null)
let pos = { top: 0, left: 0, x: 0, y: 0 } let pos = { top: 0, left: 0, x: 0, y: 0 }
function mouseMoveHandler(e: any) { function mouseMoveHandler(e: MouseEvent) {
const dx = e.clientX - pos.x const dx = e.clientX - pos.x
const dy = e.clientY - pos.y const dy = e.clientY - pos.y
@@ -23,7 +23,7 @@ function mouseUpHandler() {
document.removeEventListener('mouseup', mouseUpHandler) document.removeEventListener('mouseup', mouseUpHandler)
} }
function mouseDownHandler(e: any) { function mouseDownHandler(e: MouseEvent) {
if (treeRef.value === null) return if (treeRef.value === null) return
treeRef.value.style.cursor = 'grabbing' treeRef.value.style.cursor = 'grabbing'
treeRef.value.style.userSelect = 'none' treeRef.value.style.userSelect = 'none'
+24 -6
View File
@@ -24,7 +24,21 @@ function newSession() {
} }
} }
const store: any = reactive({ interface Session {
status: string
graph: FileGraph
pwd: string
hints: string[]
tasks: string[]
}
interface Store {
session: Session
questId: string
quest: any // 这里需要根据实际情况定义 quest 属性的类型
}
const store: Store = reactive({
session: newSession(), session: newSession(),
questId: '', questId: '',
quest: null, quest: null,
@@ -40,7 +54,7 @@ function setQuest(questId: string) {
}) })
} }
async function setSession(session: any) { async function setSession(session: Session) {
try { try {
console.log('Setting session...', session) console.log('Setting session...', session)
store.session = session store.session = session
@@ -50,7 +64,11 @@ async function setSession(session: any) {
term.focus() term.focus()
} catch (err: any) { } catch (err: any) {
console.error(err) console.error(err)
toast.error(err.message) if (err instanceof Error) {
toast.error(err.message)
} else {
toast.error('Failed to connect to the session. Please try again later.')
}
throw err throw err
} }
} }
@@ -67,7 +85,7 @@ export async function createSession() {
} }
} }
async function getActiveSession(questId: any) { async function getActiveSession(questId: string) {
try { try {
const res = await api.post('/sessions/active', { questId }) const res = await api.post('/sessions/active', { questId })
await setSession(res.data) await setSession(res.data)
@@ -128,10 +146,10 @@ export async function init(questId: string) {
} }
function setup() { function setup() {
socket.on('terminal', (data: any) => { socket.on('terminal', (data: string) => {
term.write(data) term.write(data)
}) })
term.onData((data: any) => { term.onData((data: string) => {
socket.emit('terminal', data) socket.emit('terminal', data)
}) })
socket.on('graph', (event: { discover: FileObject[]; pwd: string }) => { socket.on('graph', (event: { discover: FileObject[]; pwd: string }) => {
+7 -7
View File
@@ -1,28 +1,28 @@
/* eslint-disable max-classes-per-file */ /* eslint-disable max-classes-per-file */
export class TooManyRequestsError extends Error { export class TooManyRequestsError extends Error {
constructor(message: string | undefined) { constructor(message: string) {
super(message) super(message)
this.name = 'TooManyRequestsError' this.name = 'TooManyRequestsError'
} }
} }
export class ValidationError extends Error { export class ValidationError extends Error {
constructor(message: string | undefined) { constructor(message: string) {
super(message) super(message)
this.name = 'ValidationError' this.name = 'ValidationError'
} }
} }
export class UnauthorizedError extends Error { export class UnauthorizedError extends Error {
constructor(message: string | undefined) { constructor(message: string) {
super(message) super(message)
this.name = 'UnauthorizedError' this.name = 'UnauthorizedError'
} }
} }
export class LoadQuestError extends Error { export class LoadQuestError extends Error {
questId: any questId: string
constructor(message: string | undefined, questId: any) { constructor(message: string, questId: string) {
super(message) super(message)
this.name = 'LoadQuestError' this.name = 'LoadQuestError'
this.questId = questId this.questId = questId
@@ -30,8 +30,8 @@ export class LoadQuestError extends Error {
} }
export class LoadSessionError extends Error { export class LoadSessionError extends Error {
questId: any questId: string
constructor(message: string | undefined, questId: any) { constructor(message: string, questId: string) {
super(message) super(message)
this.name = 'LoadSessionError' this.name = 'LoadSessionError'
this.questId = questId this.questId = questId
+8 -1
View File
@@ -5,7 +5,14 @@ import Background from '../components/DynamicBackground.vue'
import { TooManyRequestsError, ValidationError } from '../utils/errors' import { TooManyRequestsError, ValidationError } from '../utils/errors'
import { checkUsername, chooseUsername } from '../utils/auth' import { checkUsername, chooseUsername } from '../utils/auth'
async function check({ username, error }: { username: string; error: any }) { async function check({
username,
error,
}: {
username: string
// eslint-disable-next-line no-unused-vars
error: (msg: string) => void
}) {
if (username) { if (username) {
if (!isValidUsername(username)) { if (!isValidUsername(username)) {
error('無效的帳號名稱') error('無效的帳號名稱')