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

Type 'number[]' is missing the following properties from type '[number, number, number]': 0, 1, 2 #211

Open
skaletaPL opened this issue Mar 8, 2022 · 1 comment

Comments

@skaletaPL
Copy link

skaletaPL commented Mar 8, 2022

While trying to build an example code:
const event = { start: [2018, 5, 30, 6, 30], duration: { hours: 6, minutes: 30 }, title: 'Bolder Boulder', description: 'Annual 10-kilometer run in Boulder, Colorado', location: 'Folsom Field, University of Colorado (finish line)', url: 'http://www.bolderboulder.com/', geo: { lat: 40.0095, lon: 105.2669 }, categories: ['10k races', 'Memorial Day Weekend', 'Boulder CO'], status: 'CONFIRMED', busyStatus: 'BUSY', organizer: { name: 'Admin', email: '[email protected]' }, attendees: [ { name: 'Adam Gibbons', email: '[email protected]', rsvp: true, partstat: 'ACCEPTED', role: 'REQ-PARTICIPANT' }, { name: 'Brittany Seaton', email: '[email protected]', dir: 'https://linkedin.com/in/brittanyseaton', role: 'OPT-PARTICIPANT' } ] }

I get the following error:

Types of property 'start' are incompatible.
       Type 'number[]' is not assignable to type 'DateArray'.
         Type 'number[]' is missing the following properties from type '[number, number, number]': 0, 1, 2

npm : 6.14.14
ics: 2.35.0

Same issue discussed in #138

@generalProf
Copy link

generalProf commented Aug 13, 2022

I faced this and found the solution to it.

The problem is, when you're setting the event variable, you write the start property like so:
const event = { start: [0, 0, 0, 0, 0] }

Typescript will see "start" as number[] which is correct because it inferred the type, it's an array of numbers. But the createEvent method expects an array with 5 numbers like [Number, Number, Number, Number, Number].

To resolve the issue you have to set the type of the event object to the EventAttributes:
const event:ics.EventAttributes = { start: [0, 0, 0, 0, 0] }

This will make typescript not infer the type. As far as I'm aware this is the correct behavior from typescript.

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

2 participants