@@ -24,6 +24,19 @@ ambient namespaces:
24
24
const rootProgram = 'root'
25
25
const tsTypePrefix = 'type:'
26
26
27
+ /**
28
+ * Detect function overloads like:
29
+ * ```js
30
+ * export function foo(a: number) {}
31
+ * export function foo(a: string) {}
32
+ * ```
33
+ * @param {Set<Object> } nodes
34
+ * @returns {boolean }
35
+ */
36
+ function isTypescriptFunctionOverloads ( nodes ) {
37
+ return [ ...nodes ] . every ( node => node . parent . type === 'FunctionDeclaration' )
38
+ }
39
+
27
40
module . exports = {
28
41
meta : {
29
42
type : 'problem' ,
@@ -34,6 +47,7 @@ module.exports = {
34
47
35
48
create : function ( context ) {
36
49
const namespace = new Map ( [ [ rootProgram , new Map ( ) ] ] )
50
+ const isTypescriptFile = / \. t s | \. t s x $ / . test ( context . getFilename ( ) )
37
51
38
52
function addNamed ( name , node , parent , isType ) {
39
53
if ( ! namespace . has ( parent ) ) {
@@ -123,6 +137,8 @@ module.exports = {
123
137
for ( let [ name , nodes ] of named ) {
124
138
if ( nodes . size <= 1 ) continue
125
139
140
+ if ( isTypescriptFile && isTypescriptFunctionOverloads ( nodes ) ) continue
141
+
126
142
for ( let node of nodes ) {
127
143
if ( name === 'default' ) {
128
144
context . report ( node , 'Multiple default exports.' )
0 commit comments