garbles / garbles/flag

Proper typing of components that use flags as parameters

Open
#62 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
374
Forks
27
PR merge metrics
No merged PRs in 30d

Description

I want to have a simple helper compent, that evaluates a flag and then either shows or hides its children, something like:
``

How can I properly type these props? I tried out several variants of
```
type OptionalContentProps =
| {
flag: KeyPathString[];

show: true;
hide?: false | undefined | null;
}
| {
flag: KeyPathString[];
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!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.