Skip to content

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

@wjhurley

Description

@wjhurley

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions