Subscribe on changes!

Type of the value property in the TextareaHTMLAttributes interface

avatar
Feb 16th 2023

Vue version

3.3.0-alpha.4

Link to minimal reproduction

https://github.com/vuejs/core/blob/4a16b204be47de546d4b3c9eb3495c370341d336/packages/runtime-dom/types/jsx.d.ts#L684

Steps to reproduce

Hello,

Shouldn't the type of the 'value' property in the TextareaHTMLAttributes interface be 'any', like in the InputHTMLAttributes interface?

https://github.com/vuejs/core/blob/4a16b204be47de546d4b3c9eb3495c370341d336/packages/runtime-dom/types/jsx.d.ts#L684

I am getting a type error with TypeScript when the value is null.

What is expected?

value?: any
(support :value to be bound to anything w/ v-model)

What is actually happening?

type error

System Info

No response

Any additional comments?

No response

avatar
Mar 20th 2023

<input> can mean anything, e.g. number or boolean, so it makes sense to be typed as any. On the other hand, <textarea> is strictly limited to texts, so I don't think it needs to accept any. You can set it to undefined anyway.

Some references: TypeScript DOM types: https://github.com/microsoft/TypeScript/blob/f64f40d20511d2d2a9eb4fcc1ad6750977be2d40/src/lib/dom.generated.d.ts#L8896 React JSX types: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/1510fcc8ca198002a13660cac2eafc2786165ce1/types/react/index.d.ts#L2458

avatar
Mar 27th 2023

But the react jsx type for input is more restricted too :

value?: string | ReadonlyArray | number | undefined;

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/1510fcc8ca198002a13660cac2eafc2786165ce1/types/react/index.d.ts#LL2256C13-L2256C13

For Vue, on input, we have "any" with no restriction, but it's very restrictive on the textarea. I find the logic strange. And it's mostly strange not being able to use "null" and forcing the use of "undefined" only for the textarea.

avatar
Mar 27th 2023

Thanks, I've read HTML documentation on MDN in more depth and realized that input's value only has a few possible types, so any is too permissive.

Nevertheless, it's another topic and should have a dedicated issue. (Though I doubt it'll change in the current major version, as it's a breaking change in types.)

avatar
Mar 28th 2023

Thank you for your feedback :) It would be cleaner on the input side to be less permissive. However, as you said, the change is a breaking change, and it won't happen right away. It's a bit annoying to have something out of sync between the input and the textarea.

I was hoping to persuade you to change the textarea type instead, while waiting to modify the input type.