dcantatore / react-rrule-builder-ts

rrule component for react with mui
MIT License
7 stars 2 forks source link

When using `<RRuleBuilder dateAdapter={AdapterDateFns} />` I get typescript compilation errors: #11

Open dcantatore opened 2 months ago

dcantatore commented 2 months ago
          When using `<RRuleBuilder dateAdapter={AdapterDateFns} />` I get typescript compilation errors:
../../node_modules/react-rrule-builder-ts/src/components/RRuleBuilder/RRuleBuilder.tsx(20,58): error TS2344: Type 'TDate' does not satisfy the constraint 'Date'.
../../node_modules/react-rrule-builder-ts/src/components/RRuleBuilder/RRuleBuilder.tsx(133,29): error TS2322: Type 'new (...args: any[]) => MuiPickersAdapter<TDate, any>' is not assignable to type 'new (...args: any) => MuiPickersAdapter<Date, any>'.
  Type 'MuiPickersAdapter<TDate, any>' is not assignable to type 'MuiPickersAdapter<Date, any>'.
    Type 'TDate' is not assignable to type 'Date'.
../../node_modules/react-rrule-builder-ts/src/store/builderStore.tsx(19,35): error TS2344: Type 'TDate' does not satisfy the constraint 'Date'.
../../node_modules/react-rrule-builder-ts/src/store/builderStore.tsx(28,47): error TS2344: Type 'TDate' does not satisfy the constraint 'Date'.
../../node_modules/react-rrule-builder-ts/src/utils/buildRRuleString.ts(11,34): error TS2344: Type 'TDate' does not satisfy the constraint 'Date'.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

it seems to work fine at runtime though.

Originally posted by @devth in https://github.com/dcantatore/react-rrule-builder-ts/issues/1#issuecomment-2346814744

dcantatore commented 2 months ago

@devth - Can you make a quick demo app to repro?

devth commented 2 months ago

Sure. Should have time later today. Would a storybook story suffice or do you want a standalone?

dcantatore commented 2 months ago

If you can make it so I can repro it, anywhere is fine. One thing to note that I had experienced is that when I changed date adapters and messed with other packages too much I would need to rm -rf node-modules and/or delete the .cache folders that are floating around

devth commented 2 months ago

Thanks for the tip. I'll see what I can do.

devth commented 1 month ago

Interestingly I couldn't repro in a new Story using AdapterDateFns.

Maybe an issue with exact dependency versions. I'm going to play with dep versions in my app and see if that resolves it.

devth commented 1 month ago

I also tried nuking node_modules but it didn't resolve. It also repros in my CI with fresh node_modules:

../../node_modules/react-rrule-builder-ts/src/components/RRuleBuilder/RRuleBuilder.tsx:20:58
Type error: Type 'TDate' does not satisfy the constraint 'Date'.

  18 |
  19 | interface RRuleBuilderProps<TDate> ***
> 20 |   dateAdapter: new (...args: any[]) => MuiPickersAdapter<TDate, any>;
     |                                                          ^
  21 |   datePickerInitialDate?: TDate;
  22 |   onChange?: (rruleString: string) => void;
  23 |   rruleString?: string;
error Command failed with exit code 1.

Currently using:

    "@mui/icons-material": "^5.16.7",
    "@mui/lab": "^5.0.0-alpha.173",
    "@mui/material": "^5.16.7",
    "@mui/styles": "^5.16.7",
    "@mui/x-data-grid": "^7.13.0",
    "@mui/x-date-pickers": "^7.13.0",
    "@mui/x-tree-view": "^7.13.0",

and

    "date-fns": "^4.0.0",

I'm switching to:

    "@mui/material": "^5.15.19",
    "@mui/x-date-pickers": "^7.6.2",

to match this project. Update: that didn't help or change the errors.

devth commented 1 month ago

One thing I realized is since I'm already using MUI I've already set my own <LocalizationProvider dateAdapter={AdapterDateFns}>. Would it be possible to rely on the context instead of requiring users to pass in the adapter?

dcantatore commented 1 month ago

I'm going to close this in the next few days if you aren't able to post a reproduction. Please let me know your progress

devth commented 1 month ago

Sorry, haven't had time to work on this. What do you think about relying on an existing LocalizationProvider being set?

dcantatore commented 1 month ago

I don't think that's the issue but I could possibly export the component pre-provider. Not a high priority at the moment

Please create a react create app or a nextjs app with the same issue, shouldn't take too long

devth commented 1 month ago

Repro code and instructions here: https://github.com/devth/rrule-builder-date-fns-repro?tab=readme-ov-file#repo-type-error

Usage is here: https://github.com/devth/rrule-builder-date-fns-repro/blob/master/src/pages/index.tsx#L19

devth commented 1 month ago

@dcantatore do you need help looking into this? We might be able to dedicate a little time. It's weird because it works perfectly at runtime - it's just the type error preventing the build from passing.

dcantatore commented 4 weeks ago

If you wouldn't mind, I'm going to be doing some more work on the package in the coming week and this is kind of low priority since its only a type issue and not an actual runtime issue

devth commented 4 weeks ago

Sure, I'll see if someone on my team can put some time on it. We'd love to use this in prod.

I realize it's just a type issue but doesn't that block all date-fn users from using this package? Or are you thinking it's not a big deal because users could just ignore the type issue (I'm not actually sure how to do that in third party packages)?