Skip to content

Commit

Permalink
feat: Add Annotating Props to Typescript page (#2068)
Browse files Browse the repository at this point in the history
* feat: Add Annotating Props to Typescript page

* Code style change based on suggestions

Co-Authored-By: pikax <david-181@hotmail.com>

* improve typescript annotation on the notificationMessage

* remove as any from Typescript Annotating Props

* removing PropValidator<T> from Typescript Annotating Props

* fix typos on Typescript Annotating Props

* improve wording on Typescript Annotating Props

Co-authored-by: Carlos <carlos.rodrigues@accountscore.com>
Co-authored-by: Kael <kaelwd@gmail.com>
  • Loading branch information
3 people authored Apr 20, 2020
1 parent a8a4e61 commit b97abcd
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/v2/guide/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,34 @@ const Component = Vue.extend({
```

If you find type inference or member completion isn't working, annotating certain methods may help address these problems. Using the `--noImplicitAny` option will help find many of these unannotated methods.



## Annotating Props

```ts
import Vue, { PropType } from 'vue'

interface ComplexMessage {
title: string,
okMessage: string,
cancelMessage: string
}
const Component = Vue.extend({
props: {
name: String,
success: { type: String },
callback: {
type: Function as PropType<() => void>
},
message: {
type: Object as PropType<ComplexMessage>,
required: true,
validator (message: ComplexMessage) {
return !!message.title;
}
}
}
})
```
If you find validator not getting type inference or member completion isn't working, annotating the argument with the expected type may help address these problems.

0 comments on commit b97abcd

Please sign in to comment.