Skip to content

Commit

Permalink
fix(eslint-plugin): [unified-signatures] crash: cannot read pro… (#1096)
Browse files Browse the repository at this point in the history
Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
  • Loading branch information
a-tarasyuk and bradzacher committed Nov 16, 2019
1 parent 9aee06c commit d1de3a7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/eslint-plugin/src/rules/unified-signatures.ts
Expand Up @@ -535,7 +535,8 @@ export default util.createRule({

// collect overloads
TSDeclareFunction(node): void {
addOverload(node, node.id.name, getExportingNode(node));
const exportingNode = getExportingNode(node);
addOverload(node, node.id?.name ?? exportingNode?.type, exportingNode);
},
TSCallSignatureDeclaration: addOverload,
TSConstructSignatureDeclaration: addOverload,
Expand Down
36 changes: 36 additions & 0 deletions packages/eslint-plugin/tests/rules/unified-signatures.test.ts
Expand Up @@ -128,6 +128,14 @@ export interface Foo {
bar(baz: string): number[];
bar(): string[];
}
`,
`
declare module "foo" {
export default function(foo: number): string[];
}
`,
`
export default function(foo: number): string[];
`,
],
invalid: [
Expand Down Expand Up @@ -649,5 +657,33 @@ export function foo(line: number, character?: number): number;
},
],
},
{
code: `
declare module "foo" {
export default function(foo: number): string[];
export default function(foo: number, bar?: string): string[];
}
`,
errors: [
{
messageId: 'omittingSingleParameter',
line: 4,
column: 40,
},
],
},
{
code: `
export default function(foo: number): string[];
export default function(foo: number, bar?: string): string[];
`,
errors: [
{
messageId: 'omittingSingleParameter',
line: 3,
column: 38,
},
],
},
],
});
1 change: 0 additions & 1 deletion packages/typescript-estree/src/ts-estree/ts-estree.ts
Expand Up @@ -1061,7 +1061,6 @@ export interface TSConstructSignatureDeclaration extends FunctionSignatureBase {
}

export interface TSDeclareFunction extends FunctionDeclarationBase {
id: Identifier;
type: AST_NODE_TYPES.TSDeclareFunction;
}

Expand Down

0 comments on commit d1de3a7

Please sign in to comment.