Type Error in Vue: properties not correctly recognized within computedRefs? #10800
Unanswered
dckz74
asked this question in
Help/Questions
Replies: 1 comment 3 replies
-
I believe this is the intended behaviour of TypeScript. It's better that you take a look at -> https://github.com/Microsoft/TypeScript/wiki/FAQ#indirect-excess-properties-are-ok. The discussion is still ongoing so I'm not sure if it's gonna be changed in the future. This is the type of the function you pass into export type ComputedGetter<T> = (oldValue?: T) => T; Then take a look this TypeScript Playground. I wrote a similar function, you will see that excess properties does not yield an error, while missing property will still give a type error. If you want to have an exact type checking, I think you will have to do this. But this is probably not what you want. const computedhumanWithHeight = computed<Human>(() => {
const value: Human = {
...human,
height: 160
}
return value
}) |
Beta Was this translation helpful? Give feedback.
3 replies
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.
-
Hello everybody!
I am kinda stuck with a problem and I do not know if this is intended or if I am missing the simple solution.
Reproduction
Here is a reproduction of my case in the Vue SFC Playground.
The issue
As you can see I have an interface called
Human
with name and surname properties and an optional age property. While I get the correct error message for myhumanWithHeight
that says:Object literal may only specify known properties, and height does not exist in type Human. ts(2353)
I do not get the same message for my
computedHumanWithHeight
. I really want to have that type safety for my computed values so that I cannot just add some random properties.This leaves me with two questions:
Greatly appreciating your answers!
Beta Was this translation helpful? Give feedback.
All reactions