Skip to content

Enum FlagSource not useable as value #345

@jhoermann

Description

@jhoermann

Problem
Since the enum FlagSource is only exported as Type from types.d.ts and not as value it can't be used in the code e.g. like this.

import { FlagSource } from 'flagsmith'

if (source === FlagSource.None) {
    ...
}

Directly comparing with the string "NONE" should be avoided (see https://typescript-eslint.io/rules/no-unsafe-enum-comparison/).
So the only workaround is using it like this:

import type { FlagSource } from 'flagsmith/types'

if (source === ('NONE' as FlagSource.NONE)) {
    ...
}

Which is not ideal.

Possible Solutions

  1. Export the enum as value e.g. from the flagsmith core file
  2. Get rid of the enum and use string literal types (https://www.typescriptcourse.com/string-literal-unions-over-enums)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions