Type of the value property in the TextareaHTMLAttributes interface
Vue version
3.3.0-alpha.4
Link to minimal reproduction
Steps to reproduce
Hello,
Shouldn't the type of the 'value' property in the TextareaHTMLAttributes interface be 'any', like in the InputHTMLAttributes interface?
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
On the other hand, <input>
can mean anything, e.g. number
or boolean
, so it makes sense to be typed as any
.<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
But the react jsx type for input is more restricted too :
value?: string | ReadonlyArray
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.
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.)
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.