rollup-plugin-dts
rollup-plugin-dts copied to clipboard
Unexpected error when using lodash
I got a type error when using lodash. If you change it to typeof, it works.
Checklist
- [x] 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 (withallowJs: true
), but this is known to cause issues. - [x] This issue is not related to rolling up
@types
. The plugin ignores these by default, unlessrespectExternal
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\[email protected]\node_modules\rollup\dist\shared\parseAst.js:282:41)
at Object.error (D:\Projects\swiper-extra-modules\node_modules\.pnpm\[email protected]\node_modules\rollup\dist\shared\parseAst.js:278:42)
at Object.error (D:\Projects\swiper-extra-modules\node_modules\.pnpm\[email protected]\node_modules\rollup\dist\shared\rollup.js:804:32)
at Object.error (D:\Projects\swiper-extra-modules\node_modules\.pnpm\[email protected]\node_modules\rollup\dist\shared\rollup.js:19612:42)
at generateDtsFromTs (file:///D:/Projects/swiper-extra-modules/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/rollup-plugin-dts/dist/rollup-plugin-dts.mjs:1833:30)
at Object.transform (file:///D:/Projects/swiper-extra-modules/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/rollup-plugin-dts/dist/rollup-plugin-dts.mjs:1842:38)
at D:\Projects\swiper-extra-modules\node_modules\.pnpm\[email protected]\node_modules\rollup\dist\shared\rollup.js:989:40