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

Type checking fails for components loaded via defineAsyncComponent #4789

Open
BlushingTomato opened this issue Sep 2, 2024 · 12 comments
Open
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first

Comments

@BlushingTomato
Copy link

Vue - Official extension or vue-tsc version

2.1.4

VSCode version

1.92.2

Vue version

2.7.16

TypeScript version

5.5.4

System Info

No response

package.json dependencies

No response

Steps to reproduce

  • Import a component via const Component = defineAsyncComponent(() => import('path/to/Component.vue')) and use it within the template.
  • Run vue-tsc --noEmit
  • Notice the error.

What is expected?

The check passing succesfully.

What is actually happening?

The following TS error:

TS2345: Argument of type '{}' is not assignable to parameter of type '(component: Component<DefaultData<never>, DefaultMethods<never>, DefaultComputed, DefaultProps, {}>) => void'.
  Type '{}' provides no match for the signature '(component: Component<DefaultData<never>, DefaultMethods<never>, DefaultComputed, DefaultProps, {}>): void'.

Link to minimal reproduction

No response

Any additional comments?

This issue started happening in 2.1.4, 2.1.2 seems to work fine.

@KazariEX
Copy link
Collaborator

KazariEX commented Sep 2, 2024

I cannot reproduce it. Could you provide a minimal reproduction?

@BlushingTomato
Copy link
Author

I tried creating a minimal reproduction, but cannot seem to reproduce it outside of our main repo 😞

I noticed that it also only happens for some components, not all of them. I'll keep looking as to what could be causing this.

@BlushingTomato
Copy link
Author

Actually managed to reproduce it, you can see it here:

Seems to happen on defineAsyncComponent instances which do not have any props passed.

@KazariEX KazariEX added bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first and removed need info labels Sep 2, 2024
@KazariEX
Copy link
Collaborator

KazariEX commented Sep 2, 2024

Enter the node_modules/.vue-global-types/vue_2.7_false.d.ts file, add the following content before line 102:

	: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
+	: T extends (...args: any) => Promise<infer R> | void ? () => R
	: T extends (...args: any) => any ? T

Could this solve your problem?

@BlushingTomato
Copy link
Author

The vue_2.7_false.d.ts file gets reset when I run the vue-tsc --noEmit command, so it keeps happening. Can I use a flag to disable that behavior?

@KazariEX
Copy link
Collaborator

KazariEX commented Sep 3, 2024

You can patch the @vue/language-core/lib/codegen/globalTypes.js file as a temporary solution.

@BlushingTomato
Copy link
Author

No, the issue sadly persists even after patching the file.

@KazariEX
Copy link
Collaborator

KazariEX commented Sep 3, 2024

It solved your repro on my machine, so I don't how to confirm the issue that occurred on your main repository :(

@BlushingTomato
Copy link
Author

I tested it on the repro on my machine too, where it failed 🤔

I've added : T extends (...args: any) => Promise<infer R> | void ? () => R after line 124 inside codegen/globalTypes, should I add it somewhere else?

@BlushingTomato
Copy link
Author

Oh my god, I cannot read. I've added it before that line and now it works. I apologize for the inconvenience and thank you for the solution.

@HryhoriiUstymenko
Copy link

Hello, I stumbled upon the same issue.
Looking forward to it being fixed!

@KazariEX
Copy link
Collaborator

The current solution is not elegant and may trigger other unexpected type inferences. We are currently unable to merge it into the main branch - please use the above workaround temporarily until then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first
Projects
None yet
Development

No branches or pull requests

3 participants