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}))
    }, [])
相关推荐
前端白袍14 小时前
Vue:如何实现一个具有复制功能的文字按钮?
前端·javascript·vue.js
new code Boy15 小时前
escape谨慎使用
前端·javascript·vue.js
奶球不是球15 小时前
elementplus组件中el-calendar组件自定义日期单元格内容及样式
javascript·css·css3
叠叠乐15 小时前
robot_state_publisher 参数
java·前端·算法
Kiri霧15 小时前
Range循环和切片
前端·后端·学习·golang
小张快跑。15 小时前
【Java企业级开发】(十一)企业级Web应用程序Servlet框架的使用(上)
java·前端·servlet
傻啦嘿哟15 小时前
实战:用Splash搞定JavaScript密集型网页渲染
开发语言·javascript·ecmascript
小白阿龙15 小时前
Flex布局子元素无法垂直居中
前端
秋田君15 小时前
前端工程化部署入门:Windows + Nginx 实现多项目独立托管与跨域解决方案
前端·windows·nginx
冰敷逆向15 小时前
苏宁滑块VMP深入剖析(一):解混淆篇
javascript·爬虫·安全·web