diff --git a/generator.ts b/generator.ts index 0e18377..3c68a04 100755 --- a/generator.ts +++ b/generator.ts @@ -90,7 +90,7 @@ function getEnumTs( case "object": { const enumValues = enumData.values.map(({ name }) => ` ${name}: "${name}"`).join(",\n"); const enumName = enumNameMap.get(enumData.name); - return `export const ${enumName} = {\n${enumValues}\n};\n\nexport type ${enumName} = (typeof ${enumName})[keyof typeof ${enumName}];`; + return `export const ${enumName} = {\n${enumValues}\n} as const;\n\nexport type ${enumName} = (typeof ${enumName})[keyof typeof ${enumName}];`; } default: throw new Error(`Unknown enumType: ${config.enumType}`); diff --git a/tests/options-behavior/expected/enumTypeObject.ts b/tests/options-behavior/expected/enumTypeObject.ts index 9756340..6701d93 100644 --- a/tests/options-behavior/expected/enumTypeObject.ts +++ b/tests/options-behavior/expected/enumTypeObject.ts @@ -4,7 +4,7 @@ export const Gender = { Male: "Male", Female: "Female", Other: "Other" -}; +} as const; export type Gender = (typeof Gender)[keyof typeof Gender]; @@ -13,7 +13,7 @@ export const DataTest = { Banana: "Banana", Orange: "Orange", Pear: "Pear" -}; +} as const; export type DataTest = (typeof DataTest)[keyof typeof DataTest]; diff --git a/tests/options-behavior/expected/enumTypeObjectPrefixSuffix.ts b/tests/options-behavior/expected/enumTypeObjectPrefixSuffix.ts index 176451b..e2ea564 100644 --- a/tests/options-behavior/expected/enumTypeObjectPrefixSuffix.ts +++ b/tests/options-behavior/expected/enumTypeObjectPrefixSuffix.ts @@ -4,7 +4,7 @@ export const eGenderEnum = { Male: "Male", Female: "Female", Other: "Other" -}; +} as const; export type eGenderEnum = (typeof eGenderEnum)[keyof typeof eGenderEnum]; @@ -13,7 +13,7 @@ export const eDataTestEnum = { Banana: "Banana", Orange: "Orange", Pear: "Pear" -}; +} as const; export type eDataTestEnum = (typeof eDataTestEnum)[keyof typeof eDataTestEnum];