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

TypeScript Object is possibly 'null' error #880

Closed
probablykasper opened this issue Mar 16, 2021 · 1 comment
Closed

TypeScript Object is possibly 'null' error #880

probablykasper opened this issue Mar 16, 2021 · 1 comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@probablykasper
Copy link

probablykasper commented Mar 16, 2021

Describe the bug
The following code:

<script lang="ts">
  type User =  { name: any } | null
  let user: User = {
    name: new Promise((resolve) => {
      setTimeout(() => {
        resolve('probablykasper')
      }, 1000)
    })
  }
</script>

{#if user}
  {#await user.name}
    Loading username
  {:then name}
    Username: {name}
  {/await}
{/if}

results in this TypeScript error:
image

To Reproduce
Repo: https://github.com/probablykasper/svelte-typescript-possibly-null-bug

Expected behavior
When await user.name is inside an if user block, user cannot be null, so there should not be any TypeScript warning

System (please complete the following information):

  • OS: macOS 10.14.6
  • IDE: VSCode
  • Plugin/Package: Svelte for VSCode, svelte-check
@probablykasper probablykasper added the bug Something isn't working label Mar 16, 2021
@probablykasper
Copy link
Author

probablykasper commented Mar 16, 2021

Similar issues: #619, #493

dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue Mar 17, 2021
By surrounding the generated block with an if-condition
sveltejs#880
dummdidumm added a commit that referenced this issue Mar 19, 2021
By surrounding the generated block with an if-condition
#880
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

2 participants