Skip to content

fix(no-undef-properties): support ...toRefs(reactive({})) in setup() return - #3134

Merged
ota-meshi merged 2 commits into
vuejs:masterfrom
chiliec:fix/no-undef-properties-torefs-reactive
Oct 9, 2026
Merged

ota-meshi merged 2 commits into
vuejs:masterfrom
chiliec:fix/no-undef-properties-torefs-reactive

Conversation

@chiliec

@chiliec chiliec commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #1915

What

vue/no-undef-properties reported every template reference as undefined when a component exposes state via ...toRefs(data) from setup(), where data is a const bound to reactive({ ... }) (the exact example from the issue). The rule only collected explicit Property entries from the setup() return object and ignored spreads.

Fix

In onVueObjectEnter, walk the setup() return object(s) for SpreadElements whose argument is a toRefs(...) call (tracked via ReferenceTracker, same approach as property-references.ts) and resolve its argument to a reactive({ ... }) object literal β€” either inline (toRefs(reactive({...}))) or through a single-definition const initialized with reactive({...}). The keys of that literal are then registered as defined setup properties. Anything not statically resolvable (non-const, reassigned, non-literal reactive arg, unknown call) is left untouched, so existing reporting is unchanged.

Tests

  • valid: const data = reactive({a, b}); return { ...toRefs(data) } (issue repro) and inline setup: () => ({ ...toRefs(reactive({ a })), ...toRefs(reactive({ b, c })) })
  • invalid: same shape but the template references c which is not in the reactive object β†’ still reported

Validation

  • npx vitest run tests/lib/rules/no-undef-properties.test.ts β†’ 81 passed (78 before + 3 new)
  • REDβ†’GREEN: with the rule change stashed, the 3 new cases fail ('a' is not defined., 'b' is not defined., and the invalid case reports extra a/b); with it restored, all pass
  • npm run build && npx vitest run tests/lib β†’ 288 files, 11624 tests passed
  • npx eslint lib/rules/no-undef-properties.ts tests/lib/rules/no-undef-properties.test.ts β†’ clean; prettier --check clean
  • npx tsc β†’ 27 pre-existing errors (all ../../../../../dist module resolution in tests before npm run build), none in the touched files; identical count on a clean checkout

Changeset added (patch). Happy to adjust.

@changeset-bot

changeset-bot Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

πŸ¦‹ Changeset detected

Latest commit: 2fe7c20

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@FloEdelmann FloEdelmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me. I have two small suggestions, see below.

Comment thread lib/rules/no-undef-properties.ts Resolved
@FloEdelmann

Copy link
Copy Markdown
Member

Thanks!

@ota-meshi ota-meshi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@ota-meshi
ota-meshi merged commit 36e4b33 into vuejs:master Oct 9, 2026
17 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 9, 2026
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.

vue/no-undef-properties have some error when use toRefs

3 participants