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

Force TypeScript definition of not primitive props #1655

Closed
przemyslawjanpietrzak opened this issue Oct 11, 2021 · 5 comments · Fixed by #1983
Closed

Force TypeScript definition of not primitive props #1655

przemyslawjanpietrzak opened this issue Oct 11, 2021 · 5 comments · Fixed by #1983

Comments

@przemyslawjanpietrzak
Copy link
Contributor

przemyslawjanpietrzak commented Oct 11, 2021

Please describe what the rule should do:
Rule should throw error/warning when component has declared prop without TypeScript definition

What category should the rule belong to?
[ ] Enforces code style (layout)
[ ] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[x] Other: Increase type coverage

Provide 2-3 code examples that this rule should warn about:

<script lang="ts">
export default {
  props: {
    total: {
      type: Object, // Error
      required: true,
    },
  },
};
</script>
<script lang="ts">
export default {
  props: {
    total: {
      type: Object as PropType<Price>, // OK
      required: true,
    },
  },
};
</script>

Additional context

Since defineComponent from vue-next or @vue/composition-api TypeScript compiler understands how properties of this are typed. However there's no way to force writing type definition of props (other than noImpliciteThis in the tsconfig). Rule like this can improve TypeScript migrations.

Please let me know what you think about it. If you like this idea I can implement this rule.

@przemyslawjanpietrzak przemyslawjanpietrzak changed the title Force TypeScript definition of no primitive props Force TypeScript definition of not primitive props Oct 12, 2021
@ota-meshi
Copy link
Member

Thank you for the rule proposal.
The rule are interesting, but I'm not familiar with typescript AST.
If you open the PR, we can add rule, but it can be difficult to maintain typescript-specific rules with this plugin.

@tatarysh
Copy link

@przemyslawjanpietrzak any news ?

@przemyslawjanpietrzak
Copy link
Contributor Author

@tatarysh I have an implementation here:

If you need this, the simplest way will be just add to as private eslint plugin

@FloEdelmann
Copy link
Member

@przemyslawjanpietrzak Thanks for sharing! Feel free to submit a pull request to add this to the official eslint-plugin-vue!

@przemyslawjanpietrzak
Copy link
Contributor Author

@FloEdelmann Thanks. I'm starting the implementation of PR

@FloEdelmann FloEdelmann linked a pull request Sep 20, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants