Skip to content

Commit

Permalink
[Fix] export: Handle function overloading in *.d.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored and ljharb committed Jan 20, 2020
1 parent 4665ec5 commit bbd166b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

## [Unreleased]
### Fixed
- [`export`]: Handle function overloading in `*.d.ts` ([#1619], thanks [@IvanGoncharov])
- [`no-absolute-path`]: fix a crash with invalid import syntax ([#1616], thanks [@ljharb])
- [`import/external-module-folders` setting] now correctly works with directories containing modules symlinked from `node_modules` ([#1605], thanks [@skozin])
- [`extensions`]: for invalid code where `name` does not exist, do not crash ([#1613], thanks [@ljharb])
Expand Down Expand Up @@ -650,6 +651,7 @@ for info on changes for earlier releases.

[#1635]: https://github.com/benmosher/eslint-plugin-import/issues/1635
[#1620]: https://github.com/benmosher/eslint-plugin-import/pull/1620
[#1619]: https://github.com/benmosher/eslint-plugin-import/pull/1619
[#1616]: https://github.com/benmosher/eslint-plugin-import/issues/1616
[#1613]: https://github.com/benmosher/eslint-plugin-import/issues/1613
[#1612]: https://github.com/benmosher/eslint-plugin-import/pull/1612
Expand Down Expand Up @@ -1096,3 +1098,4 @@ for info on changes for earlier releases.
[@bmish]: https://github.com/bmish
[@redbugz]: https://github.com/redbugz
[@kentcdodds]: https://github.com/kentcdodds
[@IvanGoncharov]: https://github.com/IvanGoncharov
8 changes: 7 additions & 1 deletion src/rules/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ const tsTypePrefix = 'type:'
*/
function isTypescriptFunctionOverloads(nodes) {
const types = new Set(Array.from(nodes, node => node.parent.type))
return types.size === 2 && types.has('TSDeclareFunction') && types.has('FunctionDeclaration')
return (
types.has('TSDeclareFunction') &&
(
types.size === 1 ||
(types.size === 2 && types.has('FunctionDeclaration'))
)
)
}

module.exports = {
Expand Down
7 changes: 7 additions & 0 deletions tests/src/rules/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ context('TypeScript', function () {
`,
}, parserConfig)),

test(Object.assign({
code: `
export function fff(a: string);
export function fff(a: number);
`,
}, parserConfig)),

test(Object.assign({
code: `
export function fff(a: string);
Expand Down

0 comments on commit bbd166b

Please sign in to comment.