Closed as not planned
Closed as not planned
Description
π Search Terms
enum
π Version & Regression Information
TypeScript: 5.5.3
- This is the behavior in every version I tried
β― Playground Link
π» Code
// FILE: ./case1.ts
export const Case1_ImageJpegType = 'image/jpeg'
export const Case1_ImagePngType = 'image/png'
// FILE: ./case2.ts
export const Case2_ImageJpegType = 'image/jpeg' as const
export const Case2_ImagePngType = 'image/png' as const
// FILE: ./test1.ts
import {Case1_ImageJpegType, Case1_ImagePngType} from './case1.js'
enum Case1 {
// WORKS AS EXPECTED
Png = Case1_ImagePngType,
Jpeg = Case1_ImageJpegType,
}
// FILE: ./test2.ts
import {Case2_ImageJpegType, Case2_ImagePngType} from './case2.js'
enum Case2 {
// FAILS WITH: Type 'string' is not assignable to type 'number' as required for computed enum member values.
Png = Case2_ImagePngType,
Jpeg = Case2_ImageJpegType,
}
π Actual behavior
Exporting a string as const
breaks string enums.
npx -p [email protected] tsc --noEmit -p tsconfig.verbatime-false.json
// FAILS with
// Type 'string' is not assignable to type 'number' as required for computed enum member values.
π Expected behavior
Exporting a string with or without as const
should not break string enums.
npx -p [email protected] tsc --noEmit -p tsconfig.verbatime-false.json
// SHOULD NOT FAIL
export const MyConst = 'MyConst'
export const MyConst = 'MyConst' as const
should behave the same when used as
import {MyConst} from './something'
enum MyEnum {
MyType = MyConst,
}