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

Proper typing of components that use flags as parameters #62

Open
mugwump opened this issue Sep 26, 2024 · 0 comments
Open

Proper typing of components that use flags as parameters #62

mugwump opened this issue Sep 26, 2024 · 0 comments

Comments

@mugwump
Copy link

mugwump commented Sep 26, 2024

I want to have a simple helper compent, that evaluates a flag and then either shows or hides its children, something like:
<OptionalContent flag={["hideFeature"]}><HideThisComponent /></OptionalContent>

How can I properly type these props? I tried out several variants of

type OptionalContentProps =
  | {
      flag: KeyPathString<MyFlags>[];
      
      show: true;
      hide?: false | undefined | null;
    }
  | {
      flag: KeyPathString<MyFlags>[];
      show?: false | undefined;
      hide: true;
    };

but can't get this to work: Inside the component, I use useFlag(flag) to evaluate the flag, so I basically need to reproduce the type that useFlag is using.

And the types used inside the lib like KeyPathString are not exported, so I had to re-write them: I am probably doing something basic wrong here, so any hint is appreciated!

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

No branches or pull requests

1 participant