refactor(types): remove `any` usages and strengthen typings across web and base (#26677)

This commit is contained in:
GuanMu 2025-10-09 21:36:42 +08:00 committed by GitHub
parent 45ae511036
commit 33b0814323
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 45 additions and 28 deletions

View File

@ -78,15 +78,15 @@ const Result: FC<IResultProps> = ({
setRespondingFalse()
}, [controlStopResponding])
const [completionRes, doSetCompletionRes] = useState<any>('')
const completionResRef = useRef<any>()
const setCompletionRes = (res: any) => {
const [completionRes, doSetCompletionRes] = useState<string>('')
const completionResRef = useRef<string>('')
const setCompletionRes = (res: string) => {
completionResRef.current = res
doSetCompletionRes(res)
}
const getCompletionRes = () => completionResRef.current
const [workflowProcessData, doSetWorkflowProcessData] = useState<WorkflowProcess>()
const workflowProcessDataRef = useRef<WorkflowProcess>()
const workflowProcessDataRef = useRef<WorkflowProcess | undefined>(undefined)
const setWorkflowProcessData = (data: WorkflowProcess) => {
workflowProcessDataRef.current = data
doSetWorkflowProcessData(data)

View File

@ -41,16 +41,16 @@ export const useWorkflowHistory = () => {
const { store: workflowHistoryStore } = useWorkflowHistoryStore()
const { t } = useTranslation()
const [undoCallbacks, setUndoCallbacks] = useState<any[]>([])
const [redoCallbacks, setRedoCallbacks] = useState<any[]>([])
const [undoCallbacks, setUndoCallbacks] = useState<(() => void)[]>([])
const [redoCallbacks, setRedoCallbacks] = useState<(() => void)[]>([])
const onUndo = useCallback((callback: unknown) => {
setUndoCallbacks((prev: any) => [...prev, callback])
const onUndo = useCallback((callback: () => void) => {
setUndoCallbacks(prev => [...prev, callback])
return () => setUndoCallbacks(prev => prev.filter(cb => cb !== callback))
}, [])
const onRedo = useCallback((callback: unknown) => {
setRedoCallbacks((prev: any) => [...prev, callback])
const onRedo = useCallback((callback: () => void) => {
setRedoCallbacks(prev => [...prev, callback])
return () => setRedoCallbacks(prev => prev.filter(cb => cb !== callback))
}, [])

View File

@ -127,7 +127,7 @@ const VarReferencePicker: FC<Props> = ({
const reactflow = useReactFlow()
const startNode = availableNodes.find((node: any) => {
const startNode = availableNodes.find((node: Node) => {
return node.data.type === BlockEnum.Start
})

View File

@ -120,7 +120,7 @@ const JsonSchemaConfig: FC<JsonSchemaConfigProps> = ({
setJson(JSON.stringify(schema, null, 2))
}, [currentTab])
const handleSubmit = useCallback((schema: any) => {
const handleSubmit = useCallback((schema: Record<string, unknown>) => {
const jsonSchema = jsonToSchema(schema) as SchemaRoot
if (currentTab === SchemaView.VisualEditor)
setJsonSchema(jsonSchema)

View File

@ -152,14 +152,16 @@ const EditCard: FC<EditCardProps> = ({
}, [isAdvancedEditing, emitPropertyOptionsChange, currentFields])
const handleAdvancedOptionsChange = useCallback((options: AdvancedOptionsType) => {
let enumValue: any = options.enum
if (enumValue === '') {
let enumValue: SchemaEnumType | undefined
if (options.enum === '') {
enumValue = undefined
}
else {
enumValue = options.enum.replace(/\s/g, '').split(',')
const stringArray = options.enum.replace(/\s/g, '').split(',')
if (currentFields.type === Type.number)
enumValue = (enumValue as SchemaEnumType).map(value => Number(value)).filter(num => !Number.isNaN(num))
enumValue = stringArray.map(value => Number(value)).filter(num => !Number.isNaN(num))
else
enumValue = stringArray
}
setCurrentFields(prev => ({ ...prev, enum: enumValue }))
if (isAdvancedEditing) return

View File

@ -180,7 +180,7 @@ const handleStream = (
let isFirstMessage = true
function read() {
let hasError = false
reader?.read().then((result: any) => {
reader?.read().then((result: ReadableStreamReadResult<Uint8Array>) => {
if (result.done) {
onCompleted?.()
return
@ -322,7 +322,21 @@ const handleStream = (
const baseFetch = base
export const upload = async (options: any, isPublicAPI?: boolean, url?: string, searchParams?: string): Promise<any> => {
type UploadOptions = {
xhr: XMLHttpRequest
method: string
url?: string
headers?: Record<string, string>
data: FormData
onprogress?: (this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => void
}
type UploadResponse = {
id: string
[key: string]: unknown
}
export const upload = async (options: UploadOptions, isPublicAPI?: boolean, url?: string, searchParams?: string): Promise<UploadResponse> => {
const urlPrefix = isPublicAPI ? PUBLIC_API_PREFIX : API_PREFIX
const token = await getAccessToken(isPublicAPI)
const defaultOptions = {
@ -331,18 +345,18 @@ export const upload = async (options: any, isPublicAPI?: boolean, url?: string,
headers: {
Authorization: `Bearer ${token}`,
},
data: {},
}
options = {
const mergedOptions = {
...defaultOptions,
...options,
headers: { ...defaultOptions.headers, ...options.headers },
url: options.url || defaultOptions.url,
headers: { ...defaultOptions.headers, ...options.headers } as Record<string, string>,
}
return new Promise((resolve, reject) => {
const xhr = options.xhr
xhr.open(options.method, options.url)
for (const key in options.headers)
xhr.setRequestHeader(key, options.headers[key])
const xhr = mergedOptions.xhr
xhr.open(mergedOptions.method, mergedOptions.url)
for (const key in mergedOptions.headers)
xhr.setRequestHeader(key, mergedOptions.headers[key])
xhr.withCredentials = true
xhr.responseType = 'json'
@ -354,8 +368,9 @@ export const upload = async (options: any, isPublicAPI?: boolean, url?: string,
reject(xhr)
}
}
xhr.upload.onprogress = options.onprogress
xhr.send(options.data)
if (mergedOptions.onprogress)
xhr.upload.onprogress = mergedOptions.onprogress
xhr.send(mergedOptions.data)
})
}
@ -432,7 +447,7 @@ export const ssePost = async (
if (!/^[23]\d{2}$/.test(String(res.status))) {
if (res.status === 401) {
if (isPublicAPI) {
res.json().then((data: any) => {
res.json().then((data: { code?: string; message?: string }) => {
if (isPublicAPI) {
if (data.code === 'web_app_access_denied')
requiredWebSSOLogin(data.message, 403)