Flagsmith / Flagsmith/flagsmith-js-client

React useFlags type issues with union type

Open
#318 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
67
Forks
45
Avg merge
1d 8h
Merged PRs (30d)
4

Description

flagsmith: 9.2.2
typescript: 5.8.3

I'm testing out Flagsmith for the first time and I'm getting some type errors when providing more than 1 flag at a time while relying on either inference or a type union. Defining the types via an interface works fine.

```ts
interface ThisWorks {
show_alert: null;
test: boolean;
}

type ThisDoesNotWork = "show_alert" | "test";

type OneWorks = "show_alert";

type Traits = "trait_1" | "trait_2";

//
const flags = useFlags(
["show_alert", "test"],
["trait_1", "trait_2"],
);

flags.show_alert;
flags.test;
flags.trait_1;
flags.trait_2;
```

I get these kinds of errors on both `flags.show_alert` and `flags.test` when using `useFlags(...)` or `useFlags(...)`:
```
Property 'show_alert' does not exist on type '({ show_alert: IFlagsmithFeature; } & { trait_1: IFlagsmithTrait; trait_2: IFlagsmithTrait; }) | ({ ...; } & { ...; })'.
Property 'show_alert' does not exist on type '{ test: IFlagsmithFeature; } & { trait_1: IFlagsmithTrait; trait_2: IFlagsmithTrait; }'. (ts 2339)
```

When using `ThisWorks`, everything works well. When using only one feature with `OneWorks`, everything works well.

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.