You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(ts-support): annotating props with validators and default values (#730)
* docs(ts-support): annotating props with validators and default values
* docs(ts-support): annotating props added prop for number array
* added missing comma
* docs(ts-support): annotating props use the Book interface in examples
Copy file name to clipboardExpand all lines: src/guide/typescript-support.md
+45-10Lines changed: 45 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -172,30 +172,65 @@ Vue does a runtime validation on props with a `type` defined. To provide these t
172
172
```ts
173
173
import { defineComponent, PropType } from'vue'
174
174
175
-
interfaceComplexMessage {
175
+
interfaceBook {
176
176
title:string
177
-
okMessage:string
178
-
cancelMessage:string
177
+
author:string
178
+
year:number
179
179
}
180
+
180
181
const Component =defineComponent({
181
182
props: {
182
183
name: String,
183
184
success: { type: String },
184
185
callback: {
185
186
type: FunctionasPropType<() =>void>
186
187
},
187
-
message: {
188
-
type: ObjectasPropType<ComplexMessage>,
189
-
required: true,
190
-
validator(message:ComplexMessage) {
191
-
return!!message.title
192
-
}
188
+
book: {
189
+
type: ObjectasPropType<Book>,
190
+
required: true
193
191
}
194
192
}
195
193
})
196
194
```
197
195
198
-
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.
196
+
::: warning
197
+
Because of a [design limitation](https://github.com/microsoft/TypeScript/issues/38845) in TypeScript when it comes
198
+
to type inference of function expressions, you have to be careful with `validators` and `default` values for objects and arrays:
0 commit comments