cal-heatmap icon indicating copy to clipboard operation
cal-heatmap copied to clipboard

Plugins have no types

Open exoRift opened this issue 1 year ago • 10 comments

Something goes wrong with Rollup when building as the plugins lose their typing (and recognition as importable modules) causing them to need manual declaration like so

declare module 'cal-heatmap/plugins/CalendarLabel'
declare module 'cal-heatmap/plugins/Tooltip'
declare module 'cal-heatmap/plugins/LegendLite'

However, this, of course, does not come with the typings the plugins should have

exoRift avatar Jun 15 '23 18:06 exoRift

I'm trying to use the the lib and it's plugins in an Angular 16 App, so far I had success with the main lib but can't import the plugins.

import LegendLite from 'cal-heatmap/plugins/LegendLite';

gives error TS2307: Cannot find module 'cal-heatmap/plugins/LegendLite' or its corresponding type declarations.

tried declare module 'cal-heatmap/plugins/LegendLite';

but it gives error TS2664: Invalid module name in augmentation, module 'cal-heatmap/plugins/LegendLite' cannot be found.

htrex avatar Jul 06 '23 21:07 htrex

Yeah, to remedy this, I forked the branch and wrote a custom build script without Rollup and have just been using that in my project directly.

exoRift avatar Jul 06 '23 23:07 exoRift

Hi @exoRift it seems your fork isn't public, would you mind sending a pull request or sharing the repo?

htrex avatar Jul 07 '23 10:07 htrex

@htrex It's under my organization.

https://github.com/guidance-analytics/cal-heatmap

It can be installed with npm i "github:guidance-analytics/cal-heatmap#ga-override-v2"

(#ga-override-v2 specifies the tag to make sure it doesn't change, or you can fork it yourself. Whichever you decide)

exoRift avatar Jul 07 '23 18:07 exoRift

thanks @exoRift It works as a temporary solution, even if it gives Uncaught SyntaxError: Cannot use import statement outside a module

htrex avatar Jul 10 '23 16:07 htrex

Yeah, I'm emitting ES code. You can either fork and change the emit, or use type: module in your package json since you're using TS anyway

exoRift avatar Jul 10 '23 17:07 exoRift

after some more experiments with cal-heatmap in an angular 16 app it seems that @exoRift first comment is the way to go, I was missing that the declare module statements must be in src/index.d.ts

htrex avatar Jul 14 '23 13:07 htrex

I'm trying to use the the lib and it's plugins in an Angular 16 App, so far I had success with the main lib but can't import the plugins. import LegendLite from 'cal-heatmap/plugins/LegendLite'; gives error TS2307: Cannot find module 'cal-heatmap/plugins/LegendLite' or its corresponding type declarations.

I encountered the same issue while using React 17 + NextJS 12. I tried adding the following declarations in src/index.d.ts:

declare module 'cal-heatmap/plugins/CalendarLabel';
declare module 'cal-heatmap/plugins/Tooltip';
declare module 'cal-heatmap/plugins/LegendLite';

However, the error persists 😥. Did I miss anything?"

Kim716 avatar Nov 29 '23 13:11 Kim716

Same with angular 17

ghost avatar Dec 30 '23 15:12 ghost

Should be fixed in master, will do some more test before releasing

wa0x6e avatar Jan 21 '24 19:01 wa0x6e