Skip to content

error when binding implicit boolean to a prop (svelte-check ) #588

@johnpapa

Description

@johnpapa

Describe the bug

Binding implicitly typed boolean variables to a prop causes an error 👇

Error Message

Error: Type 'boolean' is not assignable to type 'false'. (ts)
{message}
isOpen={showModal}
on:handleNo={closeModal}

To Reproduce
Steps to reproduce the behavior:

  1. Create a variable in a component
  export let isOpen = false;
  1. Bind this boolean variable to a boolean prop
  <div id="modal" class="modal" class:is-active={isOpen}>

For example a code snippet that is treated in a way you don't expect.

Expected behavior

This should not cause an error.

If I revise it to explicitly be a boolean, it works without any errors.

  export let isOpen: boolean = false;

But it should work with implicit booleans where we initialize to a boolean immediately as shown above.

System (please complete the following information):

  • OS: macOS
  • IDE: VSCode
  • Plugin/Package: Svelte for VSCode and svelte-check

cc @orta as per our discussion

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedFixed in master branch. Pending production release.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions