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

Unexpected error when using lodash #304

Closed
2 of 3 tasks
9romise opened this issue Apr 7, 2024 · 0 comments
Closed
2 of 3 tasks

Unexpected error when using lodash #304

9romise opened this issue Apr 7, 2024 · 0 comments

Comments

@9romise
Copy link

9romise commented Apr 7, 2024

I got a type error when using lodash. If you change it to typeof, it works.

Checklist

  • I can reproduce this issue when running this plugin on its own.
    Other plugins, such as node-resolve are known to cause issues.
  • I am running this plugin on .d.ts files generated by TypeScript.
    The plugin can consume .ts and even .js files (with allowJs: true), but this is known to cause issues.
  • This issue is not related to rolling up @types.
    The plugin ignores these by default, unless respectExternal is set. @types can contain hand-crafted code which is known to cause issues.

Code Snipped

// demo.ts
import { isBoolean, isFunction } from 'lodash-es';

type Option = boolean | ScrollToOptions | (() => boolean | ScrollToOptions);

export function demo(option: Option = true) {
  if (option === false)
    return;

  let options: ScrollToOptions = { left: 0, top: 0 };

  if (isFunction(option)) {
    const res = option() ?? true;

    if (res === false)
      return;
    else if (!isBoolean(res))
      options = res;
  }
  else if (!isBoolean(option)) {
    options = option;
  }

  return options;
}
// rollup.config.ts
import type { RollupOptions } from 'rollup';
import dts from 'rollup-plugin-dts';

const input = ['src/index.ts'];

export default [
  {
    input,
    output: [
      { file: 'dist/types/index.d.ts' },
    ],
    plugins: [dts()],
  },
] as RollupOptions;

Error Message

src/index.ts(15,17): error TS2349: This expression is not callable.
  Not all constituents of type 'true | ScrollToOptions | (() => boolean | ScrollToOptions)' are callable.
    Type 'true' has no call signatures.
src/index.ts(23,5): error TS2322: Type 'true | ScrollToOptions | (() => boolean | ScrollToOptions)' is not assignable to type 'ScrollToOptions'.
  Type 'true' has no properties in common with type 'ScrollToOptions'.

[!] (plugin dts) RollupError: [plugin dts] src/index.ts: Failed to compile. Check the logs above.
src/index.ts
    at getRollupError (D:\Projects\swiper-extra-modules\node_modules\.pnpm\rollup@4.14.1\node_modules\rollup\dist\shared\parseAst.js:282:41)
    at Object.error (D:\Projects\swiper-extra-modules\node_modules\.pnpm\rollup@4.14.1\node_modules\rollup\dist\shared\parseAst.js:278:42)
    at Object.error (D:\Projects\swiper-extra-modules\node_modules\.pnpm\rollup@4.14.1\node_modules\rollup\dist\shared\rollup.js:804:32)
    at Object.error (D:\Projects\swiper-extra-modules\node_modules\.pnpm\rollup@4.14.1\node_modules\rollup\dist\shared\rollup.js:19612:42)
    at generateDtsFromTs (file:///D:/Projects/swiper-extra-modules/node_modules/.pnpm/rollup-plugin-dts@6.1.0_rollup@4.14.1_typescript@5.4.4/node_modules/rollup-plugin-dts/dist/rollup-plugin-dts.mjs:1833:30)
    at Object.transform (file:///D:/Projects/swiper-extra-modules/node_modules/.pnpm/rollup-plugin-dts@6.1.0_rollup@4.14.1_typescript@5.4.4/node_modules/rollup-plugin-dts/dist/rollup-plugin-dts.mjs:1842:38)
    at D:\Projects\swiper-extra-modules\node_modules\.pnpm\rollup@4.14.1\node_modules\rollup\dist\shared\rollup.js:989:40
@9romise 9romise closed this as completed May 17, 2024
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

1 participant