Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overloading declaration droped #203

Open
imjuni opened this issue Jan 25, 2023 · 1 comment
Open

Overloading declaration droped #203

imjuni opened this issue Jan 25, 2023 · 1 comment

Comments

@imjuni
Copy link

imjuni commented Jan 25, 2023

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 };
@runspired
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants