-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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 / TSX] Make component events type safe, both emitting and listening #1553
Comments
I think an API for this was already discussed in this RFC and already works in the Vue 3 Beta! |
Thank you. I've overlooked it. |
Maybe I do something wrong. On a tsx file I can't do something like this: const customClick = () => {} <CustomBtn on={{ customClick }} /> I have this error:
Similar error if I try to do this (but works on runtime): <CustomBtn onCustomClick={customClick} /> |
We don't have this implemented for typing yet, since it actually relies on the template literal types feature which (I think) is going to be part of TS 4.1. |
ok thank you :) |
<FlowNode
key={node.id}
node={node}
onMessage={message}
v-slots={ {default: slots.default}}
/> Error:(103, 11) TS2322: Type '{ key: string | number; node: NodeItem; onMessage: () => void; "v-slots": { default: Slot | undefined; }; }' is not assignable to type 'IntrinsicAttributes & Partial<{}> & Pick<Readonly<{ node: NodeItem; } & {}> & VNodeProps & AllowedComponentProps & ComponentCustomProps, "style" | ... 9 more ... | "class">'.
Property 'onMessage' does not exist on type 'IntrinsicAttributes & Partial<{}> & Pick<Readonly<{ node: NodeItem; } & {}> & VNodeProps & AllowedComponentProps & ComponentCustomProps, "style" | ... 9 more ... | "class">'. Seek a solution! |
TS 4.1 has been released, I still have the error. Do you think it's possible to use the template literal types feature? |
interface IntrinsicAttributes extends ReservedProps {
[emit: string]: any
} |
Thank you for your help, update the file I'm looking forward to see a native solution to be able to keep types. |
What problem does this feature solve?
Avoid mistakes around emitting and listening component events
What does the proposed API look like?
Emitting events
Listening events
About Events type
There are some candidates about Events type specification.
1. specify argument types only
Pros: Compact
Cons: Argument names can't be specified
2. specify full function signature
Pros: Meaningful argument names can be specified
Cons: Verbose
3. hybrid
Pros: Flexible
Cons: Internal types become complicated.
The text was updated successfully, but these errors were encountered: