Skip to content

Better type safety for two way binding #1392

@probablykasper

Description

@probablykasper

Describe the bug

There's no svelte-check error when binding to a property if the property is a broader type.

To Reproduce

<script lang="ts">
  import MyComponent from './MyComponent.svelte'
  let value: Date
  $: console.log('value:', value)
</script>

<MyComponent bind:value />

MyComponent.svelte:

<script lang="ts">
  export let value: Date | null = null
</script>

{JSON.stringify(value)}

Expected behavior

There should be a type error because value is defined as Date even though it can also be null

System

  • OS: macOS
  • IDE: VSCode
  • Plugin/Package: "Svelte for VSCode", svelte-check, svelte2tsx

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy