Skip to content

test(types): add prop validator test #1769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2020

Conversation

HerringtonDarkholme
Copy link
Member

@HerringtonDarkholme HerringtonDarkholme commented Aug 3, 2020

Due to the limitation of TS, prop validator must be fully annotated.

defineComponent will produce prop type unknown in setup method because of contextual typing of object literal.

defineCopmonent({
  props: {
    validated: {
      type: String,
      validator(val) {
        return val !== ''
      }
    }
  },
  setup(props) {  
    props.validated // error, props is unknown
  }
})

The fix now is to add explicit annotation to the validator function to suppress contextual typing.

This pull request adds an example test for this.
refer to microsoft/TypeScript#38623

Due to the limitation of TS, prop validator must be fully annotated
refer to microsoft/TypeScript#38623
@yyx990803 yyx990803 merged commit 6f8bac5 into vuejs:master Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants