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

Example from README gives TypeScript error #554

Open
philwolstenholme opened this issue Aug 25, 2023 · 1 comment
Open

Example from README gives TypeScript error #554

philwolstenholme opened this issue Aug 25, 2023 · 1 comment
Labels
question Further information is requested

Comments

@philwolstenholme
Copy link

Hi, thanks for all your work on this package :)

I might have found a documentation issue or perhaps a bug?

Copying this from the examples in the README:

<Feature name="v2">
  {(isEnabled: boolean) =>
    isEnabled ? <h1>My App v2</h1> : <h1>My App v1</h1>
  }
</Feature>;

Gives me this TypeScript warning:

Type '(isEnabled: boolean) => JSX.Element' is not assignable to type 'ReactNode | ((hasFeature: boolean | FeatureGroup) => Element)'.
  Type '(isEnabled: boolean) => JSX.Element' is not assignable to type '(hasFeature: boolean | FeatureGroup) => Element'.
    Types of parameters 'isEnabled' and 'hasFeature' are incompatible.
      Type 'boolean | FeatureGroup' is not assignable to type 'boolean'.
        Type 'FeatureGroup' is not assignable to type 'boolean'.ts(2322)

My TS skills aren't good enough to debug this myself but I got the sense that perhaps a feature may have been added since the examples were added?

This gives no warning, but I'm not sure I'm handling the possibility of isEnabled being a FeatureGroup here:

<Feature name="v2">
  {(isEnabled) => (isEnabled ? <h1>My App v2</h1> : <h1>My App v1</h1>)}
</Feature>;
@philwolstenholme philwolstenholme added the question Further information is requested label Aug 25, 2023
@jabberhams
Copy link
Contributor

I'm late to the game but this is just a documentation issue. Proper syntax would be:

<Feature name="v2">
  {(isEnabled) =>
    isEnabled ? <h1>My App v2</h1> : <h1>My App v1</h1>
  }
</Feature>

The extra boolean type comes from the Feature component definition.

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

No branches or pull requests

2 participants