Closed
Description
π Search Terms
const enum
π Version & Regression Information
not sure, i think it has been like this for a long time, still present in latest version 5.7.2
β― Playground Link
π» Code
export const enum Test {
A = 300,
B = 123
}
const testFn = (a: Test) => a
testFn(Test.A)
// error as expected
testFn(2)
const testIndirectCall = (a: number) => testFn(a) // it should error here as well
// literal type
export type TestLiteralType = 300 | 123
const testFn2 = (a: TestLiteralType) => a
testFn2(Test.A)
// error as expected
testFn2(2)
const testIndirectCall2 = (a: number) => testFn2(a) // error as expected
π Actual behavior
as noted in above
π Expected behavior
as noted in above
Additional information about the issue
No response
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
RyanCavanaugh commentedon Jan 23, 2025
number
assignable toenum
is intentional; see #26362 (comment) and others. When the number is literal and we can see it's out-of-range, that's also an intentional error. The difference in behavior in different inputs is therefore expected.taozhou-glean commentedon Jan 23, 2025
i see, thanks