React 开发报错整理

1、'yield' expression implicitly results in an 'any' type because its containing generator lacks a return-type annotation.

复制代码
function* handleSignin(action: SigninAction) {
    console.log(action, 'handleSignin')
    try{
        let res: any = yield call(axios.post, `${API}/signin`, action.payload)
        yield put(signinSuccess())
    }catch(error:any) {
        alert(error.response.data.error)
        yield put(signinFail(error.response.data.error))
    }
    
}

function* handleSignin(action: SigninAction): any {
    console.log(action, 'handleSignin')
    try{
        let res: any = yield call(axios.post, `${API}/signin`, action.payload)
        yield put(signinSuccess())
    }catch(error:any) {
        alert(error.response.data.error)
        yield put(signinFail(error.response.data.error))
    }
    
}

2、React Hook "useActive" is called conditionally. React Hooks must be called in the exact same order in every component render

复制代码
function useActive(currentPath:string, path:string) {
    return currentPath === path ? 'ant-menu-item-selected' : ''
}

function getDashboardUrl() {
    let url = '/user/dashboard'
    if(isAuth()) {
        const {
            user: {role} 
        } = isAuth() as Jwt
        if(role === 1) {
            url = '/admin/dashboard'
        }
    }
    return url
}

function getDashboardUrl() {
    let url = '/user/dashboard'
    if(isAuth()) {
        const {
            user: {role} 
        } = isAuth() as Jwt
        if(role === 1) {
            url = '/admin/dashboard'
        }
    }
    return url
}


function useActive(currentPath:string, path:string) {
    return currentPath === path ? 'ant-menu-item-selected' : ''
}

3、An interface can only extend an object type or intersection of object types with statically known members

是类和接口不能 implement / extends 联合类型的类型别名。就像你用 interface 去 extends 一个 class 或另一个 interface 是可以的,但是你不能去 extends 联合类型。

复制代码
interface PrivateRouteProps extends RouteProps {}

type PrivateRouteProps = RouteProps & {}

4、An argument for 'defaultValue' was not provided

5、Argument of type 'RcFile | undefined' is not assignable to parameter of type 'string | Blob'.
Type 'undefined' is not assignable to type 'string | Blob'.

6、Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.

复制代码
const {productId} = useParams<{ productId: string }>()
    useEffect(() => {
        
        dispatch(getDetailProduct({productId}))
    }, [])

const {productId} = useParams<{ productId: string }>()
    useEffect(() => {
        //dispatch(getDetailProduct({productId: productId!}))
        dispatch(getDetailProduct({productId: productId as string}))
    }, [])
相关推荐
90后的晨仔3 分钟前
🔍Vue 模板引用(Template Refs)全解析:当你必须操作 DOM 时
前端·vue.js
90后的晨仔4 分钟前
👂 Vue 侦听器(watch)详解:监听数据的变化
前端·vue.js
90后的晨仔24 分钟前
深入浅出 Vue 的 computed:不仅仅是“计算属性”那么简单!
前端·vue.js
Nan_Shu_61439 分钟前
学习:入门uniapp Vue3组合式API版本(17)
前端·vue.js·学习·uni-app
止观止1 小时前
Remix框架:高性能React全栈开发实战
前端·react.js·前端框架·remix
萌萌哒草头将军1 小时前
🚀🚀🚀 深入探索 Node.js v22.18.0 新特性;默认支持运行 ts 文件了!
前端·typescript·node.js
安心不心安2 小时前
React ahooks——副作用类hooks之useThrottleFn
前端·javascript·react.js
秋田君2 小时前
Vue3 + WebSocket网页接入弹窗客服功能的完整实现
前端·javascript·websocket·网络协议·学习
浪里行舟2 小时前
一网打尽 Promise 组合技:race vs any, all vs allSettled,再也不迷糊!
前端·javascript·vue.js
Antonio9152 小时前
【网络编程】WebSocket 实现简易Web多人聊天室
前端·网络·c++·websocket