Skip to content

Commit 65dd690

Browse files
committed
feat: add const modifier to Enum function to simplify the enum initialization
Closed #6
1 parent bb098d0 commit 65dd690

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
# enum-plus Changelog
44

5+
## 2.3.2
6+
7+
2025-6-8
8+
9+
### Features
10+
11+
- 🛠 Add `const` modifier to Enum function to simplify the enum initialization. Inline initializations no longer requires `as const`. Thanks to @otomad.
12+
13+
```diff
14+
import { Enum } from 'enum-plus';
15+
16+
const MyEnum = Enum({
17+
Foo: 1,
18+
Bar: 2,
19+
- } as const);
20+
+ });
21+
```
22+
523
## 2.3.1
624

725
2025-6-7

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "enum-plus",
3-
"version": "2.3.1",
3+
"version": "2.3.2",
44
"description": "A drop-in replacement for native enum. Like native enum but much better!",
55
"keywords": [
66
"enum",

src/enum.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let enumExtensions: Record<string, unknown> | undefined;
3030
* @returns Enum collection | 枚举集合
3131
*/
3232
export function Enum<
33-
T extends EnumInit<K, V>,
33+
const T extends EnumInit<K, V>,
3434
K extends EnumKey<T> = EnumKey<T>,
3535
V extends EnumValue = ValueTypeFromSingleInit<T[K], K>,
3636
>(init: T, options?: EnumInitOptions<T, K, V>): IEnum<T, K, V> & EnumExtension<T, K, V>;
@@ -52,15 +52,15 @@ export function Enum<
5252
*/
5353
export function Enum<
5454
// eslint-disable-next-line @typescript-eslint/no-explicit-any
55-
T extends Record<string, any>,
55+
const T extends Record<string, any>,
5656
K extends EnumKey<T> = EnumKey<T>,
5757
V extends EnumValue = ValueTypeFromSingleInit<T[K], K>,
5858
>(
5959
init: T[],
6060
options?: EnumInitOptions<T, K, V>
6161
): IEnum<StandardEnumInit<string, V>, string, V> & EnumExtension<T, K, V>;
6262
export function Enum<
63-
T extends EnumInit<K, V>,
63+
const T extends EnumInit<K, V>,
6464
K extends EnumKey<T> = EnumKey<T>,
6565
V extends EnumValue = ValueTypeFromSingleInit<T[K], K>,
6666
>(init: T | T[], options?: EnumInitOptions<T, K, V>): IEnum<T, K, V> & EnumExtension<T, K, V> {

0 commit comments

Comments
 (0)