Subscribe on changes!

Prop with validator breaks prop types for component

avatar
Oct 23rd 2020

Version

3.0.2

Reproduction link

https://codesandbox.io/s/blissful-darwin-mi9ul

Steps to reproduce

Try to access props.type

What is expected?

No error

What is actually happening?

Property 'type' does not exist on type 'Readonly<...


Removing the validator or using as Prop<string> fixes the error, but it should be inferred without breaking the component.

avatar
Oct 26th 2020

Use arrow function instead, or explicitly add an annotation to this: validator(this: void, val: string){ ... }

avatar
Oct 26th 2020

Ah yeah it's https://github.com/vuejs/vue/issues/8679 again, thanks.

avatar
Nov 21st 2020

I would like to add that this is a design limitation in TypeScript; see this issue microsoft/TypeScript#38845. And I believe that the example under Annotating Props in the docs will have this problem as well.

avatar
Nov 21st 2020

/cc @vuejs/docs

avatar
Dec 22nd 2020

Documentation as been amended with proper instructions, we can close this here.

avatar
Mar 10th 2021

Still encountered the same issue even if following doc... (vue 3.0.7, typescript 4.2.3) https://github.com/vuejs/vue-next/issues/2738#issuecomment-795080280