Skip to content

feat(define-props-declaration): add autofix to type-based declaration - #3235

Open
ValentinYoushkevich wants to merge 6 commits into
vuejs:masterfrom
ValentinYoushkevich:feat/define-props-declaration-autofix
Open

ValentinYoushkevich wants to merge 6 commits into
vuejs:masterfrom
ValentinYoushkevich:feat/define-props-declaration-autofix

Conversation

@ValentinYoushkevich

@ValentinYoushkevich ValentinYoushkevich commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

This picks up #2466 by @mpiniarski, who agreed to hand it over. It adds an autofix to vue/define-props-declaration that turns a runtime defineProps({...}) into a single-line type-based declaration and moves defaults into withDefaults(). I went through the review there: nothing throws, there is no try/catch, and whatever can't be converted exactly just gets no fix, including array declarations like defineProps(['kind']), validator, a non-literal required, unknown constructors, spreads and comments. Props without required: true become optional, Function maps to (...args: any[]) => any, and the separate interface option is gone. I also checked that @vue/compiler-sfc generates the same runtime props for the fixed code: for X as PropType<T> the fix is applied only when T is declared in the file (or is a built-in type) and the compiler infers it as the same constructors, so imported and generic types get no fix. It is an autofix rather than a suggestion because the result is equivalent; the one exception is a PropType of a local enum whose member types differ from the constructor, where only the dev-mode type check changes.

Closes #2465

Convert a runtime defineProps() declaration to a type-based one when the
conversion keeps the props' runtime behavior, and skip the fix otherwise.
@changeset-bot

changeset-bot Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: caf84a5

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 Minor

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

…ay the same

- wrap function types in parentheses inside unions
- for `X as PropType<T>`, infer the runtime type of `T` like
  `@vue/compiler-sfc` from declarations in the file and skip the fix
  unless it matches `X`, including the `Boolean` casting order; imported,
  qualified and generic types get no fix
- skip the fix for arrays that would collapse to one type with a
  default, destructured props with defaults, duplicate option keys,
  `__proto__` and a local declaration shadowing `Record`

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.

Add autofix to define-props-declaration: transform runtime syntax to type-based syntax

1 participant