【问题标题】:'=>' expected. TS1005 for Redux Action Interface?'=>' 预期。 TS1005 用于 Redux 操作接口?
【发布时间】:2020-04-13 10:00:35
【问题描述】:

我不确定我在这里遗漏了什么,下面是我从 Typescript 中的 esLint 得到的错误截图:

代码本身在下面,这是整个文件,我做错了什么吗?这应该是某些 redux 的操作,但我可能对 typescript 语法了解得不够多,无法弄清楚它为什么给我这个警告,或者如何在不执行@ts-ignore 的情况下绕过它,但这似乎是个警察出去。这里关于我发现的 TS1005 错误的所有其他问题并不真正适用于我所看到的这种情况。

这是完整的代码:

interface ISignIn {
    (credentials: {email: string, password: string}): (dispatch: Function, getState: Function, getFirebase: any)
};

export const SignIn: ISignIn = (credentials) => {

    return (dispatch, getState, { getFirebase }) => {
        const firebase = getFirebase();

        firebase.auth().signInWithEmailAndPassword(
            credentials.email,
            credentials.password
        ).then(() => {
            dispatch({ type: 'LOGIN_SUCCESS' });
        }).catch((error: any) => {
            dispatch({ type: 'LOGIN_ERROR', error });
        });

    }
}

我错过了什么?

【问题讨论】:

  • 应该是type,而不是interface。之后,复制与实际函数中相同的箭头函数语法

标签: reactjs typescript redux interface react-redux


【解决方案1】:

添加异步操作的返回类型。例如:

(credentials: {email: string, password: string}): (dispatch: Function, getState: Function, getFirebase: any) => void

【讨论】:

    猜你喜欢
    • 2018-05-14
    • 1970-01-01
    • 2019-05-09
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    • 2023-03-25
    • 2018-03-06
    • 2013-08-20
    相关资源
    最近更新 更多