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

Open
opened 2026-02-21 20:06:19 -05:00 by yindo · 2 comments
Owner

Originally created by @coding-ice on GitHub (Nov 7, 2025).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for refactoring, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Description

Runtime Code Bloat

Enums generate additional runtime code, increasing bundle size:

enum Status {
  Active = 'active',
  Inactive = 'inactive'
}

// Compiled JavaScript
var Status;
(function (Status) {
    Status["Active"] = "active";
    Status["Inactive"] = "inactive";
})(Status || (Status = {}));

Recommended Alternatives

const Status = {
  Active: 'active',
  Inactive: 'inactive',
} as const;

type Status = typeof Status[keyof typeof Status]; // 'active' | 'inactive'

Motivation

No response

Additional Context

No response

Originally created by @coding-ice on GitHub (Nov 7, 2025). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for refactoring, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Description ## Runtime Code Bloat Enums generate additional runtime code, increasing bundle size: ```ts enum Status { Active = 'active', Inactive = 'inactive' } // Compiled JavaScript var Status; (function (Status) { Status["Active"] = "active"; Status["Inactive"] = "inactive"; })(Status || (Status = {})); ``` ## Recommended Alternatives ```ts const Status = { Active: 'active', Inactive: 'inactive', } as const; type Status = typeof Status[keyof typeof Status]; // 'active' | 'inactive' ``` ### Motivation _No response_ ### Additional Context _No response_
yindo added the good first issuerefactorstatus: accepting prs labels 2026-02-21 20:06:19 -05:00
Author
Owner

@hyoban commented on GitHub (Jan 15, 2026):

I do not like enum either. But considering this is a big change, I recommend enabling a lint rule for it first.

@hyoban commented on GitHub (Jan 15, 2026): I do not like enum either. But considering this is a big change, I recommend enabling a lint rule for it first. - https://www.typescriptlang.org/docs/handbook/enums.html - https://www.totaltypescript.com/why-i-dont-like-typescript-enums - https://github.com/antfu/eslint-config/pull/760 - https://www.totaltypescript.com/erasable-syntax-only
Author
Owner

@jubinsoni commented on GitHub (Jan 24, 2026):

adding enum restrict rule is resulting in 3000+ warnings which is not letting the pr pass
@hyoban how do we approach this as we cannot raise a single pr with 3000+ changes ?

my opinion is that possible we can break this into sub-tasks and move module by module or directory by directory

Let me know your thoughts

Image
@jubinsoni commented on GitHub (Jan 24, 2026): adding enum restrict rule is resulting in 3000+ warnings which is not letting the pr pass @hyoban how do we approach this as we cannot raise a single pr with 3000+ changes ? my opinion is that possible we can break this into sub-tasks and move module by module or directory by directory Let me know your thoughts <img width="2118" height="558" alt="Image" src="https://github.com/user-attachments/assets/24c5d433-40a4-45c9-b3c6-5484e24f75a1" />
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#20210