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}))
    }, [])
相关推荐
袁煦丞3 分钟前
极空间变身全能私有云+1Panel傻瓜式部署:cpolar内网穿透实验室第618个成功挑战
前端·程序员·远程工作
袁煦丞5 分钟前
10.15-1 Reader电子书管理神器搭配极空间私有云:cpolar内网穿透实验室第488个成功挑战
前端·程序员·远程工作
ZHOUYUANN27 分钟前
我用JavaScript复刻了某宝的小游戏动物大迁徙消消乐
前端·javascript·游戏开发
Asort27 分钟前
JavaScript设计模式(十三)——责任链模式:构建灵活高效的请求处理链
前端·javascript·设计模式
_Mya_30 分钟前
后端接口又改了?让 Apifox MCP 帮你自动同步类型定义
前端·人工智能·mcp
_AaronWong31 分钟前
一键搞定UniApp WiFi连接!这个Vue 3 Hook让你少走弯路
前端·微信小程序·uni-app
摸着石头过河的石头34 分钟前
JavaScript继承与原型链:揭开对象传承的神秘面纱
前端·javascript
_大学牲35 分钟前
Flutter 之魂 GetX🔥(二)全面解析路由管理
前端·flutter
星链引擎35 分钟前
客服机器人面向初学者的通俗版
前端