Skip to content

ref: Avoid enum usage #16922

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

Merged
merged 1 commit into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions packages/browser/src/integrations/featureFlags/openfeature/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ export const StandardResolutionReasons = {
STALE: 'STALE',
ERROR: 'ERROR',
} as const;
export enum ErrorCode {
PROVIDER_NOT_READY = 'PROVIDER_NOT_READY',
PROVIDER_FATAL = 'PROVIDER_FATAL',
FLAG_NOT_FOUND = 'FLAG_NOT_FOUND',
PARSE_ERROR = 'PARSE_ERROR',
TYPE_MISMATCH = 'TYPE_MISMATCH',
TARGETING_KEY_MISSING = 'TARGETING_KEY_MISSING',
INVALID_CONTEXT = 'INVALID_CONTEXT',
GENERAL = 'GENERAL',
}

type ErrorCode =
| 'PROVIDER_NOT_READY'
| 'PROVIDER_FATAL'
| 'FLAG_NOT_FOUND'
| 'PARSE_ERROR'
| 'TYPE_MISMATCH'
| 'TARGETING_KEY_MISSING'
| 'INVALID_CONTEXT'
| 'GENERAL';

export interface Logger {
error(...args: unknown[]): void;
warn(...args: unknown[]): void;
Expand Down
31 changes: 14 additions & 17 deletions packages/core/src/utils/syncpromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
import { isThenable } from './is';

/** SyncPromise internal states */
const enum States {
/** Pending */
PENDING = 0,
/** Resolved / OK */
RESOLVED = 1,
/** Rejected / Error */
REJECTED = 2,
}
const STATE_PENDING = 0;
const STATE_RESOLVED = 1;
const STATE_REJECTED = 2;

type State = typeof STATE_PENDING | typeof STATE_RESOLVED | typeof STATE_REJECTED;

// Overloads so we can call resolvedSyncPromise without arguments and generic argument
export function resolvedSyncPromise(): PromiseLike<void>;
Expand Down Expand Up @@ -46,12 +43,12 @@ type Executor<T> = (resolve: (value?: T | PromiseLike<T> | null) => void, reject
* but is not async internally
*/
export class SyncPromise<T> implements PromiseLike<T> {
private _state: States;
private _state: State;
private _handlers: Array<[boolean, (value: T) => void, (reason: any) => any]>;
private _value: any;

public constructor(executor: Executor<T>) {
this._state = States.PENDING;
this._state = STATE_PENDING;
this._handlers = [];

this._runExecutor(executor);
Expand Down Expand Up @@ -135,7 +132,7 @@ export class SyncPromise<T> implements PromiseLike<T> {

/** Excute the resolve/reject handlers. */
private _executeHandlers(): void {
if (this._state === States.PENDING) {
if (this._state === STATE_PENDING) {
return;
}

Expand All @@ -147,11 +144,11 @@ export class SyncPromise<T> implements PromiseLike<T> {
return;
}

if (this._state === States.RESOLVED) {
if (this._state === STATE_RESOLVED) {
handler[1](this._value as unknown as any);
}

if (this._state === States.REJECTED) {
if (this._state === STATE_REJECTED) {
handler[2](this._value);
}

Expand All @@ -161,8 +158,8 @@ export class SyncPromise<T> implements PromiseLike<T> {

/** Run the executor for the SyncPromise. */
private _runExecutor(executor: Executor<T>): void {
const setResult = (state: States, value?: T | PromiseLike<T> | any): void => {
if (this._state !== States.PENDING) {
const setResult = (state: State, value?: T | PromiseLike<T> | any): void => {
if (this._state !== STATE_PENDING) {
return;
}

Expand All @@ -178,11 +175,11 @@ export class SyncPromise<T> implements PromiseLike<T> {
};

const resolve = (value: unknown): void => {
setResult(States.RESOLVED, value);
setResult(STATE_RESOLVED, value);
};

const reject = (reason: unknown): void => {
setResult(States.REJECTED, reason);
setResult(STATE_REJECTED, reason);
};

try {
Expand Down
6 changes: 1 addition & 5 deletions packages/react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,7 @@ export type Navigation = NavigationStates[keyof NavigationStates];
export type RouteData = any;
export type Fetcher = any;

export declare enum HistoryAction {
Pop = 'POP',
Push = 'PUSH',
Replace = 'REPLACE',
}
type HistoryAction = 'POP' | 'PUSH' | 'REPLACE';

export interface RouterState {
historyAction: Action | HistoryAction | any;
Expand Down
Loading