-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Incorrect "Property is used before its initialization" error with body-less arrow functions #45182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I upgraded to TS 4.7.4, problem persists. |
Can you post an example? OP's code does not error in the 4.7 Playground |
@RyanCavanaugh please have a look! It's so confused! It looks like has some trouble with |
@RyanCavanaugh On TypeScript 4.8.2, when having target set to ES2022 and enabled |
Does this also address cases where the property name is used in a static field? In a static field, the object should be fully constructed so the property name should be accessible. declare function assert(condition: boolean): asserts condition;
class Person {
// Unexpected Error: Property 'name' is used before its initialization
static initial_name_length = new Person().name.length;
// fixed with an IIFE:
static initial_name_length_fix = (() => new Person().name.length)();
name = 'Alice';
}
assert(new Person().name === 'Alice');
assert(Person.initial_name_length === 5);
assert(Person.initial_name_length_fix === 5); |
Bug Report
🔎 Search Terms
Property is used before its initialization
arrow function
body
property
initializer
constructor parameter
useDefineForClassFields
🕗 Version & Regression Information
>= 3.8.3
⏯ Playground Link
Playground link with relevant code
💻 Code
useDefineForClassFields
must betrue
🙁 Actual behavior
With
useDefineForClassFields: true
there's an error when the arrow function has no body🙂 Expected behavior
There should be no error
The text was updated successfully, but these errors were encountered: