-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
TypeScript: Typed Function Props #9692
Labels
Comments
pikax
pushed a commit
to pikax/vue
that referenced
this issue
Mar 18, 2019
pikax
pushed a commit
to pikax/vue
that referenced
this issue
Mar 18, 2019
kiku-jw
pushed a commit
to kiku-jw/vue
that referenced
this issue
Jun 18, 2019
This was referenced Aug 29, 2019
This was referenced Sep 22, 2019
This was referenced Oct 26, 2019
This was referenced Dec 5, 2019
Lostlover
pushed a commit
to Lostlover/vue
that referenced
this issue
Dec 10, 2019
This was referenced Dec 21, 2019
This was referenced Jan 21, 2020
This was referenced Feb 24, 2020
This was referenced Mar 4, 2020
This was referenced Mar 28, 2020
This was referenced Apr 15, 2020
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What problem does this feature solve?
Get type checking for function passed as prop to a component.
Currently, it is possible to use
PropType
to get better typing on props passed to a component.For example:
In this example, the
user
prop will be correctly typed by the TypeScript type checker.This however doesn't work with function props, the following example...
... yields the following error:
What does the proposed API look like?
As converting to
unknown
first is somewhat unwieldy (and seems not to work in a SFC Vetur setup, maybe this should be looked into separately), it would be nice to have a helper function exposed by Vue such as the following...... which would allow writing the following:
I would be willing to write a PR for this, but I'm not sure where to put the definition of the
TypedFunctionProp
function as it can't be put in the declaration file.I'm also completely open to having a different name for that function. Maybe
FunctionPropType
is more consistent. I've actually switched toFnPropType
in the project I'm working on, as it's relatively short, and is consistent with thePropType
name.The text was updated successfully, but these errors were encountered: