[Vue + Typescript] Issue casting props to types

Hi all,

I have been running into an issue trying to cast Vue props to their types. If I attempt to cast them using

testIntProp: Object as () => TestInt

in the prop definition, within the prop section, the type is PropValidator<TestInt> but if I then reference that prop in a computed function, it shows it as an any. This is for both for built-in types as well as interfaces/types that I define. If I define a new variable in the computed function and cast the type there, then all works as expected but I would rather avoid that. However, if I don’t do it that way, I get the following compile error in testOne(): Property 'TestField' does not exist on type 'ComputedOptions<any> | (() => any)'. Property 'TestField' does not exist on type 'ComputedOptions<any>'.

I also already have ‘strict’ set to true in my ts.config file.

Here are some pictures showing my issue:

Thanks in advanced!

Upon further investigation, this is not limited to just the properties. If I define a return type for computed properties or data, it is showing up as type ‘any’ everywhere else in the code.

For instance, if I have the following computed property:

return 'test'
const a = this.computedOne
return ''

the type of a is showing up as any.

Any ideas? Am I misunderstanding how to use typescript in vue or do I have some sort of incorrect settings? Or is this a bug I should report?

Thanks again!

I’m having a very similar problem. Were you able to figure this out yet?

I’m not sure what exactly was causing the issue but I know it was related to different package versions. If you use vue-cli 4 to initialize your project, everything should work correctly since it has built in typescript support.