kekeh / angular-mydatepicker

Angular datepicker and date range picker :date:
https://kekeh.github.io/angular-mydatepicker/
MIT License
1 stars 11 forks source link

CalendarComponent: Object is possibly 'undefined' on 0.4.4 #31

Closed aleksandar-kandzhichki closed 4 years ago

aleksandar-kandzhichki commented 4 years ago

Hello, while building angular project with strict null type checks, I am getting the following error: image

Issue comes from here: https://github.com/kekeh/angular-mydatepicker/blob/84ec9f07f904e4c7977f9f171eeff5a4dbedf5b0/projects/angular-mydatepicker/src/lib/components/calendar/calendar.component.html#L2

In the interface for options it says styles are nullable, so in the calendar component there should be check if they exist - or make sure they exist https://github.com/kekeh/angular-mydatepicker/blob/84ec9f07f904e4c7977f9f171eeff5a4dbedf5b0/projects/angular-mydatepicker/src/lib/interfaces/my-options.interface.ts#L57

kekeh commented 4 years ago

Actually it shouldn't be undefined. The value comes from here: https://github.com/kekeh/angular-mydatepicker/blob/84ec9f07f904e4c7977f9f171eeff5a4dbedf5b0/projects/angular-mydatepicker/src/lib/services/angular-mydatepicker.config.service.ts#L53

The default config values are read here: https://github.com/kekeh/angular-mydatepicker/blob/84ec9f07f904e4c7977f9f171eeff5a4dbedf5b0/projects/angular-mydatepicker/src/lib/angular-mydatepicker.input.ts#L70

Options are passed to calendar component here: https://github.com/kekeh/angular-mydatepicker/blob/84ec9f07f904e4c7977f9f171eeff5a4dbedf5b0/projects/angular-mydatepicker/src/lib/angular-mydatepicker.input.ts#L328

aleksandar-kandzhichki commented 4 years ago

@kekeh I see, but it is still issue with the types - in the type you say it is possibly undefined, so when using it it would guess you might not have it image

(this produces error with strictNullChecks: true in TsConfig) Maybe there should be added an ! to assert TS that it will be there?:
image

kekeh commented 4 years ago

Ok. I will check that soon.

aleksandar-kandzhichki commented 4 years ago

I can give you a stackblitz with reproduction if needed, but basically adding it in the tsconfig should reproduce the error. I forked the project and fixed it there for me, so it is building properly now, but still would be good to be included here :)

kekeh commented 4 years ago

Let me know how you fix it?

aleksandar-kandzhichki commented 4 years ago

https://github.com/aleksandar-kandzhichki/angular-mydatepicker/commit/98284778439434d608e222956f718ccb94ed16ac

I personally prefer this approach - where you make sure even if it is undefined, you would add some valid value there.

The other option is what I showed in the picture - add ! after the stylesData so you assure TS that the property will not be undefined

kekeh commented 4 years ago

Looks good. I am happy if you can create a pull request from this change :-)

kekeh commented 4 years ago

Fixed in version 0.4.5.