Skip to content

Commit bbd166b

Browse files
IvanGoncharovljharb
authored andcommitted
[Fix] export: Handle function overloading in *.d.ts
1 parent 4665ec5 commit bbd166b

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
66

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

651652
[#1635]: https://github.com/benmosher/eslint-plugin-import/issues/1635
652653
[#1620]: https://github.com/benmosher/eslint-plugin-import/pull/1620
654+
[#1619]: https://github.com/benmosher/eslint-plugin-import/pull/1619
653655
[#1616]: https://github.com/benmosher/eslint-plugin-import/issues/1616
654656
[#1613]: https://github.com/benmosher/eslint-plugin-import/issues/1613
655657
[#1612]: https://github.com/benmosher/eslint-plugin-import/pull/1612
@@ -1096,3 +1098,4 @@ for info on changes for earlier releases.
10961098
[@bmish]: https://github.com/bmish
10971099
[@redbugz]: https://github.com/redbugz
10981100
[@kentcdodds]: https://github.com/kentcdodds
1101+
[@IvanGoncharov]: https://github.com/IvanGoncharov

src/rules/export.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ const tsTypePrefix = 'type:'
3636
*/
3737
function isTypescriptFunctionOverloads(nodes) {
3838
const types = new Set(Array.from(nodes, node => node.parent.type))
39-
return types.size === 2 && types.has('TSDeclareFunction') && types.has('FunctionDeclaration')
39+
return (
40+
types.has('TSDeclareFunction') &&
41+
(
42+
types.size === 1 ||
43+
(types.size === 2 && types.has('FunctionDeclaration'))
44+
)
45+
)
4046
}
4147

4248
module.exports = {

tests/src/rules/export.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ context('TypeScript', function () {
132132
`,
133133
}, parserConfig)),
134134

135+
test(Object.assign({
136+
code: `
137+
export function fff(a: string);
138+
export function fff(a: number);
139+
`,
140+
}, parserConfig)),
141+
135142
test(Object.assign({
136143
code: `
137144
export function fff(a: string);

0 commit comments

Comments
 (0)