Friday, February 23, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  8] [ 3]  / answers: 1 / hits: 10451  / 4 Years ago, fri, july 10, 2020, 12:00:00

I have an object in Typescript that I am destructuring in order to extract a partial object. However, it fails my linter check:


async someFunction(username: string): Promise<UserDTO> {
const userEntity = await getUserByUsernameAsync(username);

if (userEntity ) {
const { password, ...result } = userEntity ;
return result;
}

return null;
}

As you can see, the above code grabs an object and strips out some parts of the object that we don't want to return, and returns the rest of the object.


However, the linter gives a warning:


warning  'password' is assigned a value but never used      @typescript-eslint/no-unused-vars

The object destructuring is assigning passport to a value and result to another object value and passport is the one that isn't being used. How do I fix this issue in order to pass the linter?


More From » typescript

 Answers
3

You can disable this verification for rest siblings adding "@typescript-eslint/no-unused-vars": ["error", { "ignoreRestSiblings": true }] to your list of rules in eslintrc.js.


Example:


module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: [
"@typescript-eslint",
],
extends: [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
rules: {
"@typescript-eslint/no-unused-vars": ["error", { "ignoreRestSiblings": true }]
},
settings: {
react: {
version: "detect"
}
}
};


You can also opt for disabling the linting rule for that line altogether adding this to the line above it:


// eslint-disable-next-line @typescript-eslint/no-unused-vars

[#3226] Wednesday, July 8, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
victorr

Total Points: 193
Total Questions: 86
Total Answers: 105

Location: Pitcairn Islands
Member since Thu, Jun 24, 2021
3 Years ago
victorr questions
Fri, Nov 13, 20, 00:00, 3 Years ago
Sat, Jul 25, 20, 00:00, 4 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
Mon, Aug 19, 19, 00:00, 5 Years ago
;