wmcmahan / react-native-calendar-events

📆 React Native Module for iOS and Android Calendar Events
MIT License
906 stars 292 forks source link

Type error when updating event without startDate #441

Open LaikaTheSpaceDog opened 1 year ago

LaikaTheSpaceDog commented 1 year ago

When updating an existing event, I get a typescript error as it's expecting a startDate to be passed as a parameter even though this field should only be required when creating an event, not updating an existing event.

RNCalendarEvents.saveEvent('Updated: My Event, {
          id,
          notes: 'Foo bar',
        });

Error:

Argument of type '{ id: string; notes: string; }' is not assignable to parameter of type 'CalendarEventWritable'.
  Property 'startDate' is missing in type '{ id: string; notes: string; }' but required in type 'CalendarEventWritable'.ts(2345)

Environment

System: OS: macOS 13.5.2 CPU: (10) arm64 Apple M1 Pro Memory: 84.39 MB / 16.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 16.20.0 path: ~/.nvm/versions/node/v16.20.0/bin/node Yarn: Not Found npm: version: 8.19.4 path: ~/.nvm/versions/node/v16.20.0/bin/npm Watchman: version: 2023.08.07.00 path: /opt/homebrew/bin/watchman Managers: CocoaPods: version: 1.11.3 path: /Users/oscarwales/.rvm/gems/ruby-2.7.4/bin/pod SDKs: iOS SDK: Platforms:

Steps to Reproduce

  1. Create an event using:
    
    const [lastCreatedEventId, setLastCreatedEventId] = useState('');

RNCalendarEvents.saveEvent('foo', { startDate: new Date().toISOString(), calendarId, }).then((eventId) => setLastCreatedEventId(eventId))

2. Attempt to then update the event:

RNCalendarEvents.saveEvent('foo: updated', { id: lastCreatedEvent, notes: 'THIS IS A TEST', });


### Expected Behavior

There should be no type errors

### Actual Behavior

Get the following type error:

Argument of type '{ id: string; notes: string; }' is not assignable to parameter of type 'CalendarEventWritable'. Property 'startDate' is missing in type '{ id: string; notes: string; }' but required in type 'CalendarEventWritable'.ts(2345)