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

[🔧style]: get rid of this.constructor type cast #1539

Closed
ala-n opened this issue Mar 10, 2023 · 1 comment
Closed

[🔧style]: get rid of this.constructor type cast #1539

ala-n opened this issue Mar 10, 2023 · 1 comment
Assignees
Labels
enhancement Improvements and additions to code wontfix This will not be worked on

Comments

@ala-n
Copy link
Collaborator

ala-n commented Mar 10, 2023

As an ESL architect, I want to have consistent usage of ESL approaches.
Proposed to get rid of casting this.constructor to access static variables

See and use original #1536 implementation for base classes

Example:
Instead

 class A extends ESLBaseElement {
     static b = ...;
     
     method() {
        const v = (this.constructor as typeof A).b;
        ... v ...
     }
 }

Do this:

 class A extends ESLBaseElement {
     static b = ...;
     
     // @see https://github.com/Microsoft/TypeScript/issues/3841#issuecomment-337560146
    // eslint-disable-next-line @typescript-eslint/ban-types
    override ['constructor']!: typeof A & Function;
     
     method() {
        ... this.constructor.b ...
     }
 }
@ala-n ala-n added waits triage Issue that waits to be reviewed and handled needs assignee and removed waits triage Issue that waits to be reviewed and handled labels Mar 10, 2023
@ala-n ala-n changed the title [🚀style]: get rid of this.constructor type cast [🔧style]: get rid of this.constructor type cast Mar 10, 2023
@HenadzV HenadzV self-assigned this Mar 10, 2023
@ala-n ala-n added the enhancement Improvements and additions to code label Mar 10, 2023
@ala-n ala-n added this to the ⚡ESL: 4.4.0 Minor release milestone Mar 10, 2023
@dshovchko dshovchko self-assigned this Mar 10, 2023
@ala-n ala-n linked a pull request Mar 17, 2023 that will close this issue
@ala-n
Copy link
Collaborator Author

ala-n commented Mar 17, 2023

Closed as rejected.
The reason is described in #1536
TS is not able to provide good type definition here even with the hack used in the original request.

@ala-n ala-n closed this as completed Mar 17, 2023
@ala-n ala-n added the wontfix This will not be worked on label Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements and additions to code wontfix This will not be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants