-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat: Add Annotating Props to Typescript page #2068
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
Changes from 1 commit
fb27782
c4937a1
e845d3c
98bb7f1
b581a4e
9e7ebff
bd493e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,3 +187,43 @@ 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, | ||
validation(message: ComplexMessage){ | ||
pikax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return !!message.title; | ||
} | ||
}, | ||
notificationMessage: { | ||
type: Object as PropType<ComplexMessage>, | ||
required: true, | ||
// without argument type | ||
validation: function(message){ | ||
return !!message.title; | ||
} as (arg: ComplexMessage) => boolean | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think anyone would ever do this, and it's very similar to the previous example. A better one would be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense |
||
} | ||
} | ||
}) | ||
``` | ||
If you find type inference or member completion isn’t working, annotating prop with `PropValidator<T>` may help address it. | ||
|
Uh oh!
There was an error while loading. Please reload this page.