ESLint prefer-const rules is stating variable should be Const even though it IS reassigned

Viewed 373

This is happening in one of my Jasmine Test files.

ESLint states that the let variable: "files" isn't reassigned, and so it should be a const. However literally a few lines below (128) it's reassigned, and so if I make the fix there's an error.

I may end up making it a const, then change 128 to push the File into the array. But I'm curious as to why it's saying it's never reassigned, could there be an issue with my ESLint config or something?

Screenshot:

eslint prefer-const error

1 Answers

files isn't reassigned - it's declared once (at line 121) and then initialized later (in line 128). According to this ESLint rule, you could unify both statements and rewrite them as:

const files = [{ name: 'launch.json' } as File];
Related