'timer' is never reassigned. Use 'const' instead.
1const TIMEOUT = 5000;
2
3export const getHTMLImageElement = (src: string) => new Promise<HTMLImageElement>((resolve, reject) => {
4 let timer = setTimeout(() => { 5 reject(`Image load timed out in ${TIMEOUT}ms. src: ${src}`);
6 }, TIMEOUT);
7 const img = new Image();
'ready' is never reassigned. Use 'const' instead.
20let scale: number;
21const PATCH_SIZE = 32;
22let resolver = () => {};
23let ready = new Promise<void>(r => { 24 resolver = r;
25});
26
Description
Variables that are never re-assigned a new value after their initial declaration should be declared with the const
keyword.
This prevents the programmer from erroneously re-assigning to a read-only variable, and informs those reading the code that a variable is a constant value.
Bad Practice
let pi = Math.PI
for (let x of xs) {
use(x);
}
let { a, b } = object;
use(a, b);
Recommended
const pi = Math.PI
for (const x of xs) {
use(x);
}
const { a, b } = object;
use(a, b);