dx: improve cryptic TypeScript error when passing object literal to defineModel default #15029
T0miii
started this conversation in
General Discussions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Following the recent strict type updates to defineModel (introduced around PR #14968), passing a raw object literal as a default value now correctly fails compilation. This forces developers to use a factory function () => ({}), aligning the type definitions with correct Vue runtime behavior.
However, the resulting TypeScript overload error is highly cryptic and difficult for developers to parse, causing sudden friction when build pipelines fail during patch updates.
Proposed Solution / Suggestion
While the enforcement of the factory function is completely correct from a runtime perspective, the DX could be drastically improved.
Could we introduce a targeted type check or an explicit error type helper? If a user passes a non-primitive type that is not a function to default, it would be ideal if the compiler could explicitly emit something like:
Type error: Object and Array defaults for defineModel must use a factory function.
BR
All reactions