Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot use an array of data #73

Closed
itaysmalia opened this issue Nov 26, 2020 · 3 comments
Closed

cannot use an array of data #73

itaysmalia opened this issue Nov 26, 2020 · 3 comments

Comments

@itaysmalia
Copy link

itaysmalia commented Nov 26, 2020

I have a very simple component:

<script lang="typescript">
  import { gql } from "@apollo/client";
  import { query } from "svelte-apollo";
  interface User {
    name: string;
    id: number;
  }

  let users = query<{ users: User[] }>(gql`
    {
      users {
        id
        name
      }
    }
  `);
</script>

{#if $users.loading}
  <h1>Loading</h1>
{:else if $users.error}
  <h2>{$users.error}</h2>
{:else if $users.data}
  {#each $users.data.users as user (user.id)}
    <li>{user.name}</li>
  {/each}
{/if}
<ul />

and I have a super annoying ts warning that says Object is possibly 'null' or 'undefined'.ts(2533) on $users.data.users inside the #each loop.

@itaysmalia
Copy link
Author

I think it might be a svelte-typescript issue...
I will post the issue in the svelte repo and close this one, I'll update this one for any update in the new one.

@rarenatoe
Copy link

Can you point us where the fix to this is?

I am new to typescript and I keep getting similar errors:

/Users/.../project/src/routes/index.svelte:61:10
Error: Object is of type 'unknown'. (ts)
        {:else}
                {#each $products.data.products as product}
                        <li>{product.title} by {product.author.name}</li>

It throws it at the call of $products.data, and both calls of product.

@bompi88
Copy link

bompi88 commented Jul 17, 2022

Yes, I get this as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants