Skip to content

fix(types): keep VueWrapper for findComponent with an any-typed selector - #2973

Open
ondrhn wants to merge 1 commit into
vuejs:mainfrom
ondrhn:fix/issue-2972-types-keep-vuewrapper-for
Open

ondrhn wants to merge 1 commit into
vuejs:mainfrom
ondrhn:fix/issue-2972-types-keep-vuewrapper-for

Conversation

@ondrhn

@ondrhn ondrhn commented Oct 18, 2026

Copy link
Copy Markdown

Since 2.5.1, findComponent() called with a selector typed as any returns DOMWrapper<Node> instead of VueWrapper<any>, so .vm, .props() and .emitted() on the result no longer type-check. A selector ends up as any whenever the component's type cannot be inferred, for example a component imported from an untyped JS module, or type-aware linting that resolves .vue imports without Vue language support. Only the types changed; the runtime behavior is the same.

The generic-SFC overload added in #2934 was declared before the DefinedComponent overload in BaseWrapper.findComponent. An any argument is assignable to every overload, so TypeScript resolved it to the first match, and since ReturnType<any> is any, the unknown extends ReturnType<T> branch evaluated to DOMWrapper<Node>. Moving the generic-SFC overload below the DefinedComponent one restores the 2.5.0 result and matches the order findAllComponents(), getComponent() and WrapperLike.findComponent() already use. Generic SFCs keep resolving to the generic overload because their call signature has no construct signature, so they do not match DefinedComponent; test-dts/genericComponent.d-test.ts covers that.

Regression from #2934.

fix #2972

An `any` selector matches every overload, so TS picked the first one. With
the generic-SFC overload ahead of the DefinedComponent one, `ReturnType<any>`
made `unknown extends ReturnType<T>` true and the result was DOMWrapper<Node>.
@netlify

netlify Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for vue-test-utils-docs ready!

Name Link
🔨 Latest commit 65c9ee3
🔍 Latest deploy log https://app.netlify.com/projects/vue-test-utils-docs/deploys/6ad480755154bc12863374dd
😎 Deploy Preview https://deploy-preview-2973--vue-test-utils-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: findComponent() with an any-typed selector returns DOMWrapper<Node> since 2.5.1

1 participant