Skip to content

Commit b97abcd

Browse files
pikaxCarlosKaelWD
authored
feat: Add Annotating Props to Typescript page (#2068)
* feat: Add Annotating Props to Typescript page * Code style change based on suggestions Co-Authored-By: pikax <[email protected]> * 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 <[email protected]> Co-authored-by: Kael <[email protected]>
1 parent a8a4e61 commit b97abcd

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Diff for: src/v2/guide/typescript.md

+31
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,34 @@ const Component = Vue.extend({
187187
```
188188

189189
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.
190+
191+
192+
193+
## Annotating Props
194+
195+
```ts
196+
import Vue, { PropType } from 'vue'
197+
198+
interface ComplexMessage {
199+
title: string,
200+
okMessage: string,
201+
cancelMessage: string
202+
}
203+
const Component = Vue.extend({
204+
props: {
205+
name: String,
206+
success: { type: String },
207+
callback: {
208+
type: Function as PropType<() => void>
209+
},
210+
message: {
211+
type: Object as PropType<ComplexMessage>,
212+
required: true,
213+
validator (message: ComplexMessage) {
214+
return !!message.title;
215+
}
216+
}
217+
}
218+
})
219+
```
220+
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 commit comments

Comments
 (0)