infctr/eslint-plugin-typescript-sort-keys

crash in typescript-sort-keys/interface on constructor declarations

arild-haugstad opened this issue · 3 comments

As a minimal example; if we extend the ClockConstructor interface from the TypeScript documentation with an overload, so that there is something to sort, we get a crash when sorting uses getPropertyName(node) which attempts to read node.key.name, which fails on TSConstructSignatureDeclaration nodes.

Example code to lint:

interface ClockConstructor {
    new (hour: number, minute: number): ClockInterface;
    new (hour: number): ClockInterface;
}
interface ClockInterface {
    tick(): void;
}

Depending on the preferred order wrt. constructor declarations, perhaps replacing the line

return module.exports.getStaticPropertyName(node) || node.key.name || null;

in getPropertyName with

return module.exports.getStaticPropertyName(node) || (node.key && node.key.name) || null;

would be a reasonable solution?

@bfmiv Would you like to investigate?

bfmiv commented

@infctr sorry just saw this, yes I will take a look

@bfmiv Thank you