Tell us about your environment
Please show your full configuration:
module.exports = {
root: true,
env: {
node: true
},
extends: ["plugin:vue/recommended", "@vue/prettier", "@vue/typescript"],
rules: {
"no-console": process.env.NODE_ENV === "production" ? "error" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off"
},
parserOptions: {
parser: "typescript-eslint-parser"
}
};
What did you do? Please include the actual source code causing the issue.
.eslintrc.js, change plugin:vue/essential to plugin:vue/recommended to get all rulesPropOptions types to HelloWorld.vue as seen below. In this example I use PropOptions<string>, which is redundant (but still shows the problem). In practice, this would be a more complex type like an interface. https://github.com/vuejs/vue/issues/7640#issuecomment-365217858 is where I got inspiration for this typing syntax.<script lang="ts">
import Vue, { PropOptions } from "vue";
export default Vue.extend({
props: {
msg: {
type: String,
required: true
} as PropOptions<string>
}
});
</script>
What did you expect to happen?
No errors that prop msg requires a default value to be set.
$ yarn lint
yarn run v1.9.4
$ vue-cli-service lint
DONE No lint errors found!
What actually happened? Please include the actual, raw output from ESLint.
It looks like adding as PropOptions<string> trips up the parser such that it doesn't recognize that the msg prop is required and therefore doesn't need a default value
$ yarn lint
yarn run v1.9.4
$ vue-cli-service lint
error: Prop 'msg' requires default value to be set (vue/require-default-prop) at src/components/HelloWorld.vue:89:5:
87 | export default Vue.extend({
88 | props: {
> 89 | msg: {
| ^
90 | type: String,
91 | required: true
92 | } as PropOptions<string>
Thanks for posting this issue @wuservices I really like how you explained the problem. I confirmed it and it's due to the fact that typescript-eslint-parser returns an additional wrapper node in AST that I didn't thought about earlier. It's going to be a quick fix :)
@michalsnik can you close this ticket ?
Most helpful comment
Thanks for posting this issue @wuservices I really like how you explained the problem. I confirmed it and it's due to the fact that
typescript-eslint-parserreturns an additional wrapper node in AST that I didn't thought about earlier. It's going to be a quick fix :)