-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
feat: Add Annotating Props to Typescript page #2068
Conversation
src/v2/guide/typescript.md
Outdated
// 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 comment
The 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 notificationMessage: {...} as PropValidator<ComplexMessage>
with no annotation on the validator or type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense
Co-Authored-By: pikax <david-181@hotmail.com>
The only issue I can see is if you try to do callback: {
type: Function as PropType<() => void>
}, You will have an error
Surprisingly, error is gone if you fix it to be |
That issue is: vuejs/vue#9692 It will be fixed on the next release: |
Ah nice. @pikax you can probably remove that |
I didn't even notice that |
src/v2/guide/typescript.md
Outdated
validation: (message) => { | ||
return !!message.title; | ||
} | ||
} as PropValidator<ComplexMessage> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not use PropValidator
as it is not meant to be used on userland. Is there any case PropType
is not sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to provide other ways to allow forcing the PropValidator, when you don't send the validation parameter type typescript has some problems to get type explicity, it will complain about implicit 'any'.
Other way to fix this would be annotate the validation with as (message: ComplexMessage)=>boolean
or simply set the type on the parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then let's just annotate validator parameter 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no need for that example then 🙂
src/v2/guide/typescript.md
Outdated
} | ||
}) | ||
``` | ||
If you find validator not getting type inference or member completion isn't working, annotating the argument the the expected type may help address these problems; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the the
;
This ever gonna make it in? |
Adding some examples on how to annotate props with typescript