Skip to content

test(types): add prop validator test - #1769

Merged
yyx990803 merged 1 commit into
vuejs:masterfrom
HerringtonDarkholme:master
Aug 14, 2020
Merged

yyx990803 merged 1 commit into
vuejs:masterfrom
HerringtonDarkholme:master

Conversation

@HerringtonDarkholme

@HerringtonDarkholme HerringtonDarkholme commented Aug 3, 2020 •

Copy link
Copy Markdown
Member

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