Typescript 函数参数占位

问题:

如果你没有在tsconfig中设置noUnusedParameters为True的话,当你函数参数声明但没有使用的时候就会报错:’parameter’ is declared but its value is never read.可是在一些回调函数当中,我们不得不声明一个以后不会使用到的参数,比如:

function request (opts, (err, res, body) => {
    if (err) {}
    else {
        return body;
    }
});

解决方案:

使用{}占位

function request (opts, (err, {}, body) => {
    if (err) {}
    else {
        return body;
    }
});

猜你喜欢

转载自blog.csdn.net/cfarmerreally/article/details/79842046