Skip to content

TypeScript does not understand x-if #31

Open
@smtchahal

Description

@smtchahal

Describe the bug
TypeScript does not understand x-if. Inside an x-if block, the passed variable should be evaluated for truthyiness, but it is not.

To Reproduce
Steps to reproduce the behavior:

The following code should do it:

type MyNameProps = {
    children: string
}

const MyName = ({ children }: MyNameProps) => (
    <div>{children}</div>
)

type MyComponentProps = {
    name: string | null
}

const MyComponent = ({ name }: MyComponentProps) => (
    <MyName x-if={name}>{name}</MyName>
)
// ...

Expected behavior
TypeScript compiles successfully and does not show any errors. {name} gets passed as a string to <MyName>.

Actual behavior
TypeScript complains that <MyName> requires children to be of type string, but string | null was passed.

Environment

  • OS: Ubuntu 20.04
  • node version: 16.14.2
  • babel version: 7.9.0
  • version: 2.0.1
  • TypeScript version: 4.6.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions