Typescript lint "no-unused-vars" with declared tuple
Asked Answered
L

2

6

I have a line in code that looks like this:

const [full, text, url] = markdownLink.exec(match) || [null, null, '']

However I am not using full and the linter is giving me a warning.

Line 28: 'full' is assigned a value but never used

I'd like to declare the tuple like this, but I don't need full. Is there a syntactical way to fix this by skipping full?

Langlois answered 27/8, 2019 at 14:6 Comment(2)
does const [, text, url] = ... work?Swaney
Does this answer your question? How can I ignore certain returned values from array destructuring?Mendelian
B
0

This warning is because your array destructuring is doing some affectations like full = null; which is not used later.

Array destructuring is quite sexy, but not always the solution. In your case simply access to the array in a classic way.

const arr = markdownLink.exec(match) || [null, null, ''];
const text = arr[1];
const url = arr[2];
Baptlsta answered 27/8, 2019 at 15:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.