rollup-plugin-ts
rollup-plugin-ts copied to clipboard
Overloading declaration droped
Version: 3.1.1, 3.2.0 Rollup Version: 3.7.5 Operating System and version (if applicable): wsl2 Node Version (if applicable): 14.20.1 Does it work with tsc (if applicable): fine works in tsc
Reproduction
rollup-plugin-ts drop overloading declaration.
// index.ts
export { default as isError } from './isError/isError';
// isError.ts
function isError(err: unknown): Error | undefined;
function isError(err: unknown, defaultValue: Error): Error;
function isError(err?: unknown, defaultValue?: Error): Error | undefined {
if (err instanceof Error) {
return err;
}
if (
err !== undefined &&
err !== null &&
typeof err === 'object' &&
'message' in err &&
'stack' in err
) {
return err as Error;
}
if (defaultValue !== undefined && defaultValue !== null) {
return defaultValue;
}
return undefined;
}
export default isError;
Expected Behavior
I think overloading function .d.ts file like that,
declare function isError(err: unknown): Error | undefined;
declare function isError(err: unknown, defaultValue: Error): Error;
declare function isError(err?: unknown, defaultValue?: Error): Error | undefined;
export { isError };
But rollup-plugin-ts drop first declaration in generated .d.ts file.
Actual Behavior
// generated .d.ts
declare function isError(err: unknown): Error | undefined;
declare function isError(err: unknown, defaultValue: Error): Error;
export { isError };
This would be correct behavior as the final "implementation" signature is merely the fall-through combination of all overloads and not a signature that can be itself matched: thus when using declare for the type the implementation signature is unnecessary and dropped.