冗余功能。如何以其他方式返回响应?

时间:2018-08-17 08:29:49

标签: javascript typescript

function redundantFunc(){
        let response: SignInResponse = {
            user: user,
            account: account,
            company: company
        };
        return response;
}

它告诉我response的值是多余的。如何以其他方式退还? ?

4 个答案:

答案 0 :(得分:2)

您只需键入函数的返回值即可:

function redundantFunc(): SignInResponse {
    return {
        user: user,
        account: account,
        company: company
    };
}

答案 1 :(得分:1)

仅返回它,无需声明并将其分配给变量

function redundantFunc(): SignInResponse {
    return {
        user: user,
        account: account,
        company: company
    };
}

答案 2 :(得分:1)

以SignInResponse作为其属性返回对象。

function redundantFunc(){
    return {
      SignInResponse:{
        user: user,
        account: account,
        company: company
    };
}

答案 3 :(得分:0)

如果您确实要等待冗余代码,可以使用ES6对象文字:

let company = "BigCo", account = "test account", user = "mark"

const redundantFunc = () => ({response: {user, account, company}})

console.log(redundantFunc())