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}))
    }, [])
相关推荐
再学一点就睡33 分钟前
深入理解 Redux:从手写核心到现代实践(附 RTK 衔接)
前端·redux
天天进步20152 小时前
从零到一:现代化充电桩App的React前端参考
前端·react.js·前端框架
柯南二号2 小时前
【大前端】React Native Flex 布局详解
前端·react native·react.js
龙在天2 小时前
npm run dev 做了什么❓小白也能看懂
前端
_Kayo_2 小时前
React 学习笔记2 props、refs
笔记·学习·react.js
hellokai3 小时前
React Native新架构源码分析
android·前端·react native
li理3 小时前
鸿蒙应用开发完全指南:深度解析UIAbility、页面与导航的生命周期
前端·harmonyos
去伪存真4 小时前
因为rolldown-vite比vite打包速度快, 所以必须把rolldown-vite在项目中用起来🤺
前端
KubeSphere4 小时前
Kubernetes v1.34 重磅发布:调度更快,安全更强,AI 资源管理全面进化
前端
wifi歪f4 小时前
🎉 Stenciljs,一个Web Components框架新体验
前端·javascript