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

Class properties with a generic type declaration recognized as methods #84

Closed
wjhurley opened this issue Apr 11, 2023 · 1 comment
Closed

Comments

@wjhurley
Copy link

Class properties with a generic type declaration appear to be recognized as methods rather than properties as they should be. I have included my ESLint configuration, an example that recreates the issue, and a screenshot of the ESLint error.

    plugins: [
        'sort-class-members',
    ],
    rules: {
        'sort-class-members/sort-class-members': [
            2,
            {
                accessorPairPositioning: 'getThenSet',
                order: [
                    '[properties]',
                    'constructor',
                    '[methods]',
                ],
            },
        ],
    },
export default abstract class Foo<T> {
    protected abstract readonly _foo: T;

    public readonly bar: string;

    public readonly baz: string;

    protected constructor(bar: string) {
        this.bar = bar;
        this.baz = bar.trim();
    }

    public get data(): Foo<T>['_foo'] {
        if (!this._foo) {
            throw new Error('Something is missing');
        }
        return this._foo;
    }

    protected abstract parse(baz?: string): T;
    protected abstract stringify(): string;
}

image

image

@bryanrsmith
Copy link
Owner

Thanks for the report @wjhurley! Looks like it was actually the abstract, which was producing a TSAbstractPropertyDefinition node, which was not being included in the type check for properties. I believe I've fixed the issue in 1.17.1, published just now. Let me know how it works for you.

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

No branches or pull requests

2 participants