Skip to content
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

Fix initializer of instance members that reference identifiers declar… #6882

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

frost-cy
Copy link
Contributor

@frost-cy frost-cy commented Jul 17, 2024

…ed in the constructor

Motivation for features / changes

When public class fields are enabled, such cases throw a TS error similar to this.

third_party/javascript/angular_components/src/cdk/platform/platform.ts:37:29 - error TS2729: Property '_platformId' is used before its initialization.

37   isBrowser: boolean = this._platformId
                               ~~~~~~~~~~~

  third_party/javascript/angular_components/src/cdk/platform/platform.ts:87:15
    87   constructor(@Inject(PLATFORM_ID) private _platformId: Object) {}
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    '_platformId' is declared here.

This error is fixed by moving the initializer of such class members into the constructor.

This is a no-op change

See go/lsc-fix-properties-used-before-initialization

Technical description of changes

Fix initializer of instance members that reference identifiers declared in the constructor.

Screenshots of UI changes (or N/A)

N/A

Detailed steps to verify changes work correctly (as executed by you)

This is a no-op change

Alternate designs / implementations considered (or N/A)

N/A

frost-cy added 2 commits July 17, 2024 12:19
…ed in the constructor

When public class fields are enabled, such cases throw a TS error similar to this.

```
third_party/javascript/angular_components/src/cdk/platform/platform.ts:37:29 - error TS2729: Property '_platformId' is used before its initialization.

37   isBrowser: boolean = this._platformId
                               ~~~~~~~~~~~

  third_party/javascript/angular_components/src/cdk/platform/platform.ts:87:15
    87   constructor(@Inject(PLATFORM_ID) private _platformId: Object) {}
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    '_platformId' is declared here.
```

This error is fixed by moving the initializer of such class members into the constructor.

This is a no-op change 

See go/lsc-fix-properties-used-before-initialization
@frost-cy frost-cy marked this pull request as ready for review July 17, 2024 19:27
@rileyajones
Copy link
Contributor

Please run yarn fix-lint or else patch this commit

rileyajones added a commit that referenced this pull request Oct 8, 2024
#6924)

## Motivation for features / changes
See #6882 for an explanation as to why these changes are needed.
That PR was opened by an internal contributor who was having issues
fixing the lint errors the encountered.

---------

Co-authored-by: Chinthoorie <[email protected]>
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.

2 participants