Skip to content

refactor(web): convert ValidatedStatus enum to as-const in key-valida…#35749

Merged
crazywoola merged 3 commits into
langgenius:mainfrom
guangyang1206:refactor/web-key-validator-status-enum-to-as-const-27998
May 4, 2026
Merged

refactor(web): convert ValidatedStatus enum to as-const in key-valida…#35749
crazywoola merged 3 commits into
langgenius:mainfrom
guangyang1206:refactor/web-key-validator-status-enum-to-as-const-27998

Conversation

@guangyang1206
Copy link
Copy Markdown
Contributor

…tor/declarations.ts

Closes #27998

The ValidatedStatus enum generates runtime code that inflates the bundle. Convert to an as-const object with a type alias instead:

Before:
export enum ValidatedStatus {
Success = 'success',
Error = 'error',
Exceed = 'exceed',
}

After:
export const ValidatedStatus = {
Success: 'success',
Error: 'error',
Exceed: 'exceed',
} as const

export type ValidatedStatus = typeof ValidatedStatus[keyof typeof ValidatedStatus]

All 65 call sites use ValidatedStatus.Success / .Error / .Exceed property access and type annotations — no changes needed there.

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Description

What problem does this PR solve?

Issue link: Closes #27998

What did this PR do?

Converts the ValidatedStatus TypeScript enum in web/app/components/header/account-setting/key-validator/declarations.ts to an as-const object with a type alias.

Before:

export enum ValidatedStatus {
  Success = 'success',
  Error = 'error',
  Exceed = 'exceed',
}

After:

export const ValidatedStatus = {
  Success: 'success',
  Error: 'error',
  Exceed: 'exceed',
} as const

export type ValidatedStatus = typeof ValidatedStatus[keyof typeof ValidatedStatus]

Why:
TypeScript enums generate runtime IIFE boilerplate that inflates the bundle. The as-const pattern produces zero runtime overhead while preserving the same dot-notation access (ValidatedStatus.Success) and TypeScript type safety.

Scope:
All 65 call sites use ValidatedStatus.Success / .Error / .Exceed property access or type annotations — they continue to work unchanged.

Checklist

…tor/declarations.ts

Closes langgenius#27998

The ValidatedStatus enum generates runtime code that inflates the bundle.
Convert to an as-const object with a type alias instead:

  Before:
    export enum ValidatedStatus {
      Success = 'success',
      Error = 'error',
      Exceed = 'exceed',
    }

  After:
    export const ValidatedStatus = {
      Success: 'success',
      Error: 'error',
      Exceed: 'exceed',
    } as const

    export type ValidatedStatus = typeof ValidatedStatus[keyof typeof ValidatedStatus]

All 65 call sites use ValidatedStatus.Success / .Error / .Exceed property access
and type annotations — no changes needed there.
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. refactor labels Apr 30, 2026
@github-actions github-actions Bot added the web This relates to changes on the web. label Apr 30, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 4, 2026
@crazywoola crazywoola added this pull request to the merge queue May 4, 2026
Merged via the queue into langgenius:main with commit 81090ef May 4, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer refactor size:S This PR changes 10-29 lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(web): In TypeScript, the use of enums should be avoided.

2 participants