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}))
    }, [])
相关推荐
沙漠之主8 小时前
C++编程教学设计资料:从入门到实战的完整课程方案
java·前端·c++
hasty8 小时前
不上传新包,也能改变用户拿到的版本:npm dist-tag 的 OIDC 权限治理
前端·npm·node.js
Csvn8 小时前
diff 算法(虚拟 DOM Reconciliation)
前端
前端snow9 小时前
ai agent --- 文件存储
前端
Frag0ut9 小时前
Chrome四大版本获取及共存指南:Stable/Beta/Dev/Canary
前端·chrome·浏览器·dev·beta·canary·共存版
IT_陈寒11 小时前
SpringBoot自动配置坑了我一把,原来是这样绕过去的
前端·人工智能·后端
广州华水科技11 小时前
单北斗GNSS变形监测在大坝安全监测中的应用与优势
前端
zeng不错11 小时前
B站 173 个投稿活动看到眼瞎?我写了个扩展,主打一个精准打击
前端
Latchh11 小时前
前端导出的JPEG红字发糊,质量要拉到100才清楚
前端·图像处理·人工智能·计算机视觉
默_笙12 小时前
🚦 请三个 AI 考官给 RAG 打分:量化评估实战(下)
前端·javascript