proposal-decorators icon indicating copy to clipboard operation
proposal-decorators copied to clipboard

Start to disambiguate between types of initializers.

Open trusktr opened this issue 7 months ago • 2 comments

The README says here:

Field and Accessor decorators: During class construction, immediately after the field or accessor that they were applied to is initialized

This TypeScript playground example shows how the behavior did not match with what people typically consider "initialized" to mean. People consider "initialized" to mean that that a property has been created and has a value. The absence of a variable typically means the variable is not initialized yet.

After this change, it starts to be a little clearer what the actual behavior is, but the wording is still ambiguous: there are really two types of initializers here, and perhaps they need to concrete names to disambiguate so that people can understand more easily.

For example, what if they are called

  • element initializers, ("non-context initializers" in this PR's wording)
  • and context initializers

?

Then we could say something like

immediately after element initializers have finished initializing an element's value, but before the element is defined

or in the case of class fields something like

immediately after field element initializers have finished initializing a field's value, but before the field is defined on the class instance

Something along these lines will help solve the ambiguous wording.

trusktr avatar Jul 08 '25 01:07 trusktr