Whenever I attempt to utilize the bind:this
attribute in Svelte, I encounter this message in vscode:
'cardGroup' is possibly 'undefined'.js(18048)
Upon execution, the following error arises:
TypeError: Cannot read properties of undefined (reading 'childNodes')
Initially, I was working in Typescript and received an error indicating that the bound variable was not declared prior to usage.
Below is the script causing the issue:
let cardGroup;
let cardContainers = cardGroup.childNodes;
console.log(cardContainers.length);
Here's the corresponding HTML:
<div class="cardGroup" bind:this={cardGroup}>
[content]
</div>
Although it's likely that I am overlooking something, I have not come across any information on this binding that isn't performing exactly as I am trying to achieve, as far as I can determine.