Skip to content
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

SFC compiler goes into infinite loop on bad defineEmit #2973

Closed
jods4 opened this issue Jan 8, 2021 · 8 comments
Closed

SFC compiler goes into infinite loop on bad defineEmit #2973

jods4 opened this issue Jan 8, 2021 · 8 comments

Comments

@jods4
Copy link
Contributor

jods4 commented Jan 8, 2021

Version

3.0.5

Reproduction link

vitejs/vite#1436

Steps to reproduce

See link for original context.

Try to compile a bad defineEmit

// This is not correct usage
defineEmit<{ myEvent(id: number): void }>();

What is expected?

Some kind of error message?

What is actually happening?

SFC compiler goes into an infinite loop


The typing of T in defineEmit<T> does not extend Function or anything, so there's no IDE feedback on improper usage such as this example. Would be nice to harden the typing here, if possible.

@HcySunYang
Copy link
Member

The compileScript has already thrown an error for this:

3041610255734_ pic_hd

@jods4
Copy link
Contributor Author

jods4 commented Jan 10, 2021

I tried to create a minimal repro and indeed, I observed the same error as @HcySunYang. I guess I'll have to find out why in my real project it goes into an infinite loop.
Just commenting out the bad defineEmit fixes it but there must be something else required to trigger the bug.
I'll post here if I find out what is the exact condition for the bug to occur.

In the meantime, I noticed that the type validation isn't perfect.
This doesn't produce the expected error (doesn't go into a loop either):

defineEmit<((c: number) => void) | { a(n: number): void }>()

@HcySunYang
Copy link
Member

I think the TSMethodSignature syntax({ a(n: number): void }) can be supported like #2984

@posva
Copy link
Member

posva commented Jan 11, 2021

Closing in favor of #2983 since this one has no reproduction

@posva posva closed this as completed Jan 11, 2021
@LinusBorg
Copy link
Member

@posva This issue here is about defineEmit, while #2983 is about defineProps, I think we should reopen this one again.

@jods4
Copy link
Contributor Author

jods4 commented Jan 11, 2021

Yes, those are 2 different issues.
I'll reopen this one if I manage to create a minimal repro.

@posva
Copy link
Member

posva commented Jan 11, 2021

You are right, I missed the names! A new issue with a proper repro like the other one is still preferred, thanks!

@jods4
Copy link
Contributor Author

jods4 commented Jan 11, 2021

Quick heads-up: I can confirm my real project still goes in an infinite loop in Vite when I change the correct definEmit for this bad guy:

const emits = defineEmit<{ showRevision(e: 'showRevision', sha: string): void }>();

As that doesn't seem to be sufficient I'll try to work out a repro if I have the time to do so.
But as this isn't blocking (code was invalid after all), it's a bit low-priority for me.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants