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

export: Handle function overloading in '*.d.ts' #1619

Merged
merged 1 commit into from Feb 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
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
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
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