I kind of like the array destructuring in ES6.
I have a test case where I query the buttons and want to directly pull out the button variables rather than mess around with arrays, like so:
let [backButton, forwardButton]: HTMLElement[] = await screen.findAllByRole('button')
fireEvent.click(forwardButton);
However I want to repeat the destructuring later in the code, like so:
let [backButton, forwardButton]: HTMLElement[] = await screen.findAllByRole('button')
fireEvent.click(forwardButton);
//do some stuff
[backButton, forwardButton]: HTMLElement[] = await screen.findAllByRole('button')
fireEvent.click(backButton);
Unfortunately Typescript does not seem to allow me to do this.
I get an error
TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{ new (): HTMLElement; prototype: HTMLElement; }'.
Is there any way of being able to destructure twice in one block?
[backButton, forwardButton] = await screen.findAllByRole('button')