-
Notifications
You must be signed in to change notification settings - Fork 257
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: Explain how to replace attrs with props #90
Conversation
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.
Nice clarification! I love when tests work as an additional documentation.
message: 'Hello' | ||
test('assigns event listeners', async () => { | ||
const Component = { | ||
template: '<button @click="$emit(\'customEvent\', true)">Click</button>' |
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.
template: '<button @click="$emit(\'customEvent\', true)">Click</button>' | |
template: `<button @click="$emit('customEvent', true)">Click</button>` |
I think this is pretty clear, however I think it breaks the dev experience a little bit. Let me explain: to support this use-case, I had to relax the So the current typings catch The downside would be to re-introduce the WDYT? |
I did not realize this would impact the type safety. Hm. I didn't look too deeply into this PR since it was just adding what seemed to be basic tests. So you are saying that having the See what @dobromir-hristov says, since he added this test and may have specific use case. PS: I do not fully understand the down side - if we do |
Sorry if this wasn't clear. We have two options.
const Comp = defineComponent({ props: { a: String }});
mount(Comp, { props: { a: 'hello' }}) //OK
mount(Comp, { props: { a: 2 }}) // does not compile
mount(Comp, { props: { b: 2 }}) // OK, and b becomes an attribute
// but we don't know if the user _really_ meant b, or just meant a but made a mistake
const Comp = defineComponent({ props: { a: String }});
mount(Comp, { props: { a: 'hello' }}) //OK
mount(Comp, { props: { a: 2 }}) // does not compile
mount(Comp, { props: { b: 2 }}) // does not compile
mount(Comp, { attrs: { b: 2 }}) // OK, and b becomes an attribute
// no mistake possible, type safety, autocompletion When I wrote #74 I already thought aboutf that, but wanted to keep things readable and to talk with the team about the possibility to re-introduce |
I just did what Vue does. I don't use TS, so to me it was never a problem. You can get As I said, I dont have an opinion on this. |
I do not have a strong opinion either, and to be honest I didn't even think that merging props and attrs would be detrimental for typing – which makes total sense now that you have exposed it. I'm ok with splitting them if the API stays quite simple and we benefit autocompletion and type safety 👍 |
I did not even realize we had an I think it's fine to split them out. @cexbrayat are you interested in making this change? |
Sure I'll take a look and open a PR. I'm not sure this is way better, but in my experience, it always pays to have more type-safety. It's not always a pleasure to fight with vue typings but I'll see what I can come up with ;) |
So I tried something in #99 Sadly, I had not realized that for component declared with |
This is pretty self explanatory but I wanted to make sure it works.