Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Variable is possibly undefined with Svelte "bind:this={}"

$
0
0

When I try to use Svelte's bind:this attribute, I get this shown in vscode:

'cardGroup' is possibly 'undefined'.js(18048)

And when run, I get this error:

TypeError: Cannot read properties of undefined (reading 'childNodes')

I was originally working in Typescript where I got the error that the bound variable was not declared before usage.

Script:

    let cardGroup;    let cardContainers = cardGroup.childNodes;    console.log(cardContainers.length);

HTML:

<div class="cardGroup" bind:this={cardGroup}>    [content]</div>

It is entirely possible that I'm missing something but I haven't found anything using this binding that isnt doing exactly what I am, from what I can tell.


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>