icehaunter / vue3-datepicker

Simple datepicker component for Vue 3
https://icehaunter.github.io/vue3-datepicker/
MIT License
150 stars 153 forks source link

Typecheck error on v-model Date #65

Open UpcafeAdmin opened 2 years ago

UpcafeAdmin commented 2 years ago

Using

Running

yarn tsc --noEmit

Expected result

No compilation errors.

Actual result

src/views/Contact.vue:17:11 - error TS2741: Property '[Symbol.toPrimitive]' is missing in type '{ toString: () => string; toDateString: () => string; toTimeString: () => string; toLocaleString: { (): string; (locales?: string | string[] | undefined, options?: DateTimeFormatOptions | undefined): string; }; ... 38 more ...; toJSON: (key?: any) => string; }' but required in type 'Date'.

17           v-model="picked"
             ~~~~~~~

  node_modules/vue-tsc/typescript/lib/lib.es2015.symbol.wellknown.d.ts:114:5
    114     [Symbol.toPrimitive](hint: "default"): string;
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    '[Symbol.toPrimitive]' is declared here.
  node_modules/vue3-datepicker/dist/types/Datepicker.vue.d.ts:228:5
    228     modelValue?: Date | undefined;
            ~~~~~~~~~~
    The expected type comes from property 'modelValue' which is declared here on type 'Partial<{ placeholder: string; startingView: "day" | "month" | "year"; monthHeadingFormat: string; monthListFormat: string; weekdayFormat: string; inputFormat: string; weekStartsOn: number; disabled: boolean; clearable: boolean; typeable: boolean; minimumView: "day" | ... 1 more ... | "year"; }> & Omit<...> & Omit<....'
zagoskin commented 1 year ago

Currently experiencing the same issue. Our team has resolved it using it like

v-model="(picked as Date)"

But using the as keyword is giving warnings to some other people working in the project.

The weird thing is that some devs do not have the error when using plain v-model=picked as in the OP's example.

The project compiles and works for all of them nevertheless.

icehaunter commented 1 year ago

I'm not sure what could be the problem here. I can't reproduce it on a clean latest vite starter with just this project installed. A reproducible example would be appreciated and then I can help debug it. Maybe TS version is the issue?