eslint-plugin-vue icon indicating copy to clipboard operation
eslint-plugin-vue copied to clipboard

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

Open mpiniarski opened this issue 1 year ago • 3 comments

What rule do you want to change? define-props-declaration Does this change cause the rule to produce more or fewer warnings? Does not change the number of warnings. How will the change be implemented? (New option, new default behavior, etc.)? Implementing a fix method in the context.report descriptor parameter.

The rule will support separateInterface option that will opt-in to define type passed to the defineProps as an interface above defineProps call.

Please provide some example code that this change will affect: The rule will be able to autofix the following code:

      <script setup lang="ts">
      const props = defineProps({
        kind: String
      })
      </script>

transforming it to:

      <script setup lang="ts">
      const props = defineProps<{ kind: string }>()
      </script>

What does the rule currently do for this code? It des not fix it.

What will the rule do after it's changed? The rule will have the autofix feature transforming runtime syntax to type-based syntax Additional context

mpiniarski avatar May 27 '24 12:05 mpiniarski

PR welcome, but note that the autofix would need to handle quite complex cases like transforming { foo: String as PropType<'a' | 'b'>, bar: User, baz: Number } to { foo: 'a' | 'b'; bar: User; baz: number }.

FloEdelmann avatar May 27 '24 13:05 FloEdelmann

Pull request created https://github.com/vuejs/eslint-plugin-vue/pull/2466

mpiniarski avatar May 27 '24 15:05 mpiniarski

Was thinking about this transform for this rule when upgrading large project from previous minor Vue version.

zernonia avatar May 29 '24 09:05 zernonia