File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,21 @@ ambient namespaces:
24
24
const rootProgram = 'root'
25
25
const tsTypePrefix = 'type:'
26
26
27
+ /**
28
+ * Detect function overloads like:
29
+ * ```ts
30
+ * export function foo(a: number);
31
+ * export function foo(a: string);
32
+ * export function foo(a: number|string) { return a; }
33
+ * ```
34
+ * @param {Set<Object> } nodes
35
+ * @returns {boolean }
36
+ */
37
+ function isTypescriptFunctionOverloads ( nodes ) {
38
+ const types = new Set ( Array . from ( nodes , node => node . parent . type ) )
39
+ return types . size === 2 && types . has ( 'TSDeclareFunction' ) && types . has ( 'FunctionDeclaration' )
40
+ }
41
+
27
42
module . exports = {
28
43
meta : {
29
44
type : 'problem' ,
@@ -123,6 +138,8 @@ module.exports = {
123
138
for ( let [ name , nodes ] of named ) {
124
139
if ( nodes . size <= 1 ) continue
125
140
141
+ if ( isTypescriptFunctionOverloads ( nodes ) ) continue
142
+
126
143
for ( let node of nodes ) {
127
144
if ( name === 'default' ) {
128
145
context . report ( node , 'Multiple default exports.' )
Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ context('Typescript', function () {
118
118
parsers . push ( require . resolve ( '@typescript-eslint/parser' ) )
119
119
}
120
120
121
- if ( semver . satisfies ( eslintPkg . version , '<6.0.0' ) ) {
121
+ if ( semver . satisfies ( eslintPkg . version , '>=4.0.0 <6.0.0' ) ) {
122
122
parsers . push ( require . resolve ( 'typescript-eslint-parser' ) )
123
123
}
124
124
@@ -147,6 +147,14 @@ context('Typescript', function () {
147
147
` ,
148
148
} , parserConfig ) ) ,
149
149
150
+ test ( Object . assign ( {
151
+ code : `
152
+ export function fff(a: string);
153
+ export function fff(a: number);
154
+ export function fff(a: string|number) {};
155
+ ` ,
156
+ } , parserConfig ) ) ,
157
+
150
158
// namespace
151
159
test ( Object . assign ( {
152
160
code : `
You can’t perform that action at this time.
0 commit comments