-
-
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: add Props type to component constructor #6901
Comments
Actually we can do better here. By changing But this will make our complex typing file more complicated. Let's first make Vue2.5 stable and wait for more feedback. If you like this idea, please vote by emoji! |
Sounds nice. BTW, current typing loses the information about each props are required or optional, which is necessary for typed JSX. |
Fairly I don't think we can make a typing for current API, at least current TS' type system does not support it. |
I have been using library mentioned, I think first step we can do is make all props optional when using TSX with Partial, unless passing a declared interface. It will then be an enhancement when TS does support it. I think we should also create a TS issue to make awareness of this requirement linking back to this issue. I do believe we should support typed TSX out of the box with props inferred. Unfortunately but ultimately great Vue API also has more custom attributes to TSX such as scoped slots and events that we need to cater for. So interfaces will still be required as far as I can see. However where possible we should reduce the needed typing especially where duplication occurs, such as prop definitions. |
@wonderful-panda we could form requiredProps from props object no? |
@blake-newman In above example, type of |
Yes sorry forgot about that |
Hello, What's the current state of this issue? Thanks in advance. |
What problem does this feature solve?
It would be useful if we can infer Props type from component (
ExtendedVue
).For example, we can write type safe wrapper of
CreateElement
with it (or improve interface ofCreateElement
directly).What does the proposed API look like?
Now,
ExtendedVue<Vue, {}, {}, {}, { foo: string }>
andExtendedVue<Vue, {}, {}, { foo: string }, {}>
generate same type.This means we can't determine
Props
type fromExtendedVue
object.I think, easiest (and most reasonable) way to achieve this is adding types to
$props
and$data
The text was updated successfully, but these errors were encountered: