Skip to content

Start to disambiguate between types of initializers.#559

Open
trusktr wants to merge 2 commits intotc39:masterfrom
trusktr:patch-3
Open

Start to disambiguate between types of initializers.#559
trusktr wants to merge 2 commits intotc39:masterfrom
trusktr:patch-3

Conversation

@trusktr
Copy link
Contributor

@trusktr trusktr commented Jul 8, 2025

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
Copy link
Contributor Author

trusktr commented Jul 8, 2025

Whoops, I goofed up in the example, I forgot to return initial values. New example

The ambiguity on the wording remains though.

I'll update the change to reflect the correct behavior.

@trusktr
Copy link
Contributor Author

trusktr commented Jul 8, 2025

Ok the PR is updated (basically no change) but the question remains: how exactly do we name these two types of initializers so that it is clear which initializers we're talking about when we talk about them? "value initializers" or "element initializers", and "context initializers" or "non-value initializers" or "non-element initializers"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant