The following example causes 3 error Multiple default exports import/export errors, but there is only technically 1 default export the other 2 are overloads.
export default function foo(param: string): boolean;
export default function foo(param: string, param1: number): boolean;
export default function foo(param: string, param1?: number): boolean {
return param && param1;
}
There seems to be some code for checking overloads: https://github.com/benmosher/eslint-plugin-import/blob/master/src/rules/export.js#L37-L40 but this does not seem to catch this case. I added some debug logs in and the rough contents of namespace is:
root: {
default: [
{
type: 'ExportDefaultDeclaration'
},
{
type: 'ExportDefaultDeclaration'
},
{
type: 'ExportDefaultDeclaration'
}
]
}
I am running this in the following environment:
Related:
A workaround is:
function foo(param: string): boolean;
function foo(param: string, param1: number): boolean;
function foo(param: string, param1?: number): boolean {
return param && param1;
}
export default foo;
@benjie sure, that unblocks the case. But, ideally, it should be able to detect it's an overload.
PS. Might be obvious, but just in case for beginners, for non-default exports you similarly do:
function foo(param: string): boolean;
function foo(param: string, param1: number): boolean;
function foo(param: string, param1?: number): boolean {
return param && param1;
}
export { foo };
Can confirm this issue is still present. I too think that the plugin should be able to detect that this case is an overload, and not actually a case of multiple default exports.
Most helpful comment
A workaround is: