vue3-dropzone icon indicating copy to clipboard operation
vue3-dropzone copied to clipboard

getRootProps and getInputProps Type Error in Vue 3 using Typescript

Open mikemattner opened this issue 3 years ago • 4 comments

When using Vue 3 with typescript support, adding v-bind="getRootProps()" to the root element is causing the following type error:

Type '{ style: undefined; tabIndex?: number | undefined; onKeyDown: ComposeFunction | null; onFocus: ComposeFunction | null; onBlur: ComposeFunction | null; ... 5 more ...; ref: Ref<...>; }' is not assignable to type 'ElementAttrs<HTMLAttributes>'.
  Type '{ style: undefined; tabIndex?: number | undefined; onKeyDown: ComposeFunction | null; onFocus: ComposeFunction | null; onBlur: ComposeFunction | null; ... 5 more ...; ref: Ref<...>; }' is not assignable to type 'HTMLAttributes'.ts(2322)

A similar kind of type error is happening when adding v-bind="getInputProps()" to the input element:

Type '{ accept: string | string[] | undefined; multiple: boolean | undefined; style: string; type: string; onChange: ComposeFunction | null; onClick: ComposeFunction | null; autoComplete: string; tabIndex: number; ref: Ref<...>; }' is not assignable to type 'ElementAttrs<InputHTMLAttributes>'.
  Type '{ accept: string | string[] | undefined; multiple: boolean | undefined; style: string; type: string; onChange: ComposeFunction | null; onClick: ComposeFunction | null; autoComplete: string; tabIndex: number; ref: Ref<...>; }' is not assignable to type 'InputHTMLAttributes'.ts(2322)
Screen Shot 2022-07-29 at 9 53 50 AM

mikemattner avatar Jul 29 '22 13:07 mikemattner

As a temporary solution, I could pass those in using the following method:

const asAny = (fn: any) => fn as any;

and then on the item in question to eliminate typescript errors:

<input v-bind="asAny(getInputProps())" />

mikemattner avatar Jul 29 '22 17:07 mikemattner

Hi, Could you shoe me which typescript and vue version do you use, or provide a demo link? Thanks.

Yaxian avatar Jul 31 '22 01:07 Yaxian

I'm using "vue": "^3.2.27" and "typescript": "~4.5.4"

mikemattner avatar Aug 01 '22 12:08 mikemattner

Hi, Try [email protected]. It may work.

Thanks.

Yaxian avatar Aug 13 '22 07:08 Yaxian