Skip to content

refactor: replace TypeScript enums with string literal unions#885

Merged
igboyes merged 13 commits intomainfrom
igboyes/vir-2270-replace-typescript-enums-with-string-literal-unions
Apr 17, 2026
Merged

refactor: replace TypeScript enums with string literal unions#885
igboyes merged 13 commits intomainfrom
igboyes/vir-2270-replace-typescript-enums-with-string-literal-unions

Conversation

@igboyes
Copy link
Copy Markdown
Member

@igboyes igboyes commented Apr 17, 2026

Summary

Replaces all 12 remaining TypeScript enum declarations with string literal unions (and const objects where runtime values are needed). Resolves VIR-2270.

Enums removed:

  • QuickAnalyzeWorkflow (@account/types)
  • HistoryMethod (@otus/types)
  • AdministratorPermissions + internal AdministratorPermissionsLevel (@administration/utils) — replaced with plain Record consts
  • ReferenceFormMode (@references/components/ReferenceForm)
  • Molecule (@otus/types) — kept the indirection via const object + derived type, since keys differ from values (ds_dna"dsDNA")
  • sizes (@base/ProgressCircle)
  • WorkflowState, LibraryType (@samples/types)
  • ReferenceRight (@references/hooks)
  • UploadType (@uploads/types)
  • AdministratorRoleName (@administration/types)
  • Permission (@groups/types)

Each enum migrated in a separate commit so the diff stays reviewable and git bisect remains useful.

The sizes enum in src/app/theme.ts listed in the issue was already gone — no action needed.

Notes

  • npm run typecheck passes cleanly.
  • npm run check passes; warning count unchanged from the baseline (158).
  • Full vitest run: 340/340 tests pass.
  • No behaviour changes — pure type-level migration. Runtime values for Molecule, AdministratorPermissions, and AdministratorPermissionsLevel are preserved by their const replacements.

@linear
Copy link
Copy Markdown

linear bot commented Apr 17, 2026

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the codebase by replacing TypeScript enums with union types and string literals across multiple modules, including administration, account, samples, and uploads. This change simplifies the type system and improves consistency. Feedback was provided to further enhance type safety in the administration utilities by using the specific Permission type for record keys instead of generic strings.

Comment thread src/administration/utils.ts Outdated
modify_subtraction = AdministratorRoleName.FULL,
remove_file = AdministratorRoleName.FULL,
}
export const AdministratorPermissions: Record<string, AdministratorRoleName> = {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using Record<Permission, AdministratorRoleName> instead of Record<string, AdministratorRoleName> provides better type safety by ensuring all permissions are mapped to a role and preventing the use of invalid permission strings as keys. Note that you should also remove the redundant as string cast in checkAdminRoleOrPermissionsFromAccount (line 60) to satisfy the stricter typing.

Suggested change
export const AdministratorPermissions: Record<string, AdministratorRoleName> = {
export const AdministratorPermissions: Record<Permission, AdministratorRoleName> = {

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the codebase by replacing several TypeScript enums, including AdministratorRoleName, UploadType, and WorkflowState, with string union types or constant objects. These changes are applied across numerous components, hooks, and test files to use string literals. A review comment suggests improving type safety in src/administration/utils.ts by explicitly typing the keys of the AdministratorPermissions record with the Permission type.

Comment thread src/administration/utils.ts Outdated
modify_subtraction = AdministratorRoleName.FULL,
remove_file = AdministratorRoleName.FULL,
}
export const AdministratorPermissions: Record<string, AdministratorRoleName> = {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using the Permission type for the keys of AdministratorPermissions provides better type safety and ensures that all permissions are accounted for. This also allows for removing the type cast when indexing this object with a Permission value.

Suggested change
export const AdministratorPermissions: Record<string, AdministratorRoleName> = {
export const AdministratorPermissions: Record<Permission, AdministratorRoleName> = {

@igboyes igboyes merged commit 265bcc0 into main Apr 17, 2026
10 checks passed
@igboyes igboyes deleted the igboyes/vir-2270-replace-typescript-enums-with-string-literal-unions branch April 17, 2026 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant