-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Description
Bug Report
π Search Terms
preserveConstEnums, TS2450, used before its declaration
π Version & Regression Information
- This is the behavior in every version I tried: v4.9.5
β― Playground Link
Playground link with relevant code
π» Code
export const config = {
a: Foo.A,
// ^^^ Enum 'Foo' used before its declaration. (2450)
};
export const enum Foo {
A = 1,
}
π Actual behavior
There is a "used before its declaration" error with preserveConstEnums: true
, and no error with preserveConstEnums: false
.
As far as I can see this behavior was introduced including a test case in #25822.
π Expected behavior
Since the enum reference is still inlined, I don't expect a "used before its declaration" error. Alternatively I may expect the "used before its declaration" error for all const enum
declarations independently from preserveConstEnums
. Basically, I don't understand why preserveConstEnums
changes things.
I kinda understand why we want an error in the test case. The declaration after the return statement is unreachable, which might not be what the author wanted:
TypeScript/tests/baselines/reference/blockScopedEnumVariablesUseBeforeDef_preserve.js
Lines 20 to 26 in e2283e9
function foo2() { | |
return 0 /* E.A */; | |
var E; | |
(function (E) { | |
E[E["A"] = 0] = "A"; | |
})(E || (E = {})); | |
} |
I don't understand the reason in my code. I might just be missing something, though.