Skip to content

vue/require-default-prop triggers for optional props (TypeScript) #2306

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

Closed
2 tasks done
dmke opened this issue Oct 30, 2023 · 4 comments
Closed
2 tasks done

vue/require-default-prop triggers for optional props (TypeScript) #2306

dmke opened this issue Oct 30, 2023 · 4 comments

Comments

@dmke
Copy link

dmke commented Oct 30, 2023

Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version: v8.52.0
  • eslint-plugin-vue version: v9.18.1
  • Node version: v20.9.0
  • Operating System: Debian 12

Additionally:

  • @typescript-eslint/eslint-plugin, v6.9.0
  • typescript, v5.2.2

Please show your full configuration:

eslint:recommended + plugin:vue/vue3-recommended + plugin:@typescript-eslint/recommended.

Contents of .eslintrc.js
module.exports = {
  extends: ["eslint:recommended"],
  env: {
    browser: true,
    es6: true,
  },
  parserOptions: {
    sourceType: "module",
    ecmaVersion: 2022,
  },
  overrides: [{
    parser: "vue-eslint-parser",
    parserOptions: {
      parser: "@typescript-eslint/parser",
      sourceType: "module",
      ecmaVersion: 2022,
    },
    plugins: [
      "@typescript-eslint",
      "vue",
    ],
    files: ["**/*.ts", "**/*.vue"],
    extends: [
      "eslint:recommended",
      "plugin:vue/vue3-recommended",
      "plugin:@typescript-eslint/recommended",
    ],
  }],
}

What did you do?

<script setup lang="ts">
const props = withDefaults(defineProps<{
  width: number
  height?: number
}>(), {
  width: 100,
})
</script>

<template>
  {{ props }}
</template>

What did you expect to happen?

undefined ought to be a perfectly reasonable default value for the height prop, the vue/require-default-prop rule should not alert me to set a default.

For reference, this doesn't trigger vue/require-default-prop at all:

<script setup lang="ts">
defineProps<{
  width: number
  height?: number
}>()
</script>

What actually happened?

$ npx eslint UndefinedDefault.vue

/tmp/vue-require-default-prop-repro/UndefinedDefault.vue
  4:3  warning  Prop 'height' requires default value to be set  vue/require-default-prop

✖ 1 problem (0 errors, 1 warning)

Repository to reproduce this issue

https://github.com/dmke/vue-require-default-prop-repro

@FloEdelmann
Copy link
Member

FloEdelmann commented Oct 30, 2023

Duplicate of #2051. Thanks for the detailed issue description though 🙂

@FloEdelmann FloEdelmann marked this as a duplicate of #2051 Oct 30, 2023
@FloEdelmann FloEdelmann closed this as not planned Won't fix, can't repro, duplicate, stale Oct 30, 2023
@dmke
Copy link
Author

dmke commented Oct 30, 2023

Is it a duplicate? I've seen that issue, but I thought it was concerned with props consisting of ComponentObjectPropsOptions, i.e.

defineProps({ name: { type: String, default: undefined } })

versus this issue targeting the type parameters, i.e.

defineProps<{ name?: string }>()

@FloEdelmann
Copy link
Member

Hmm, it's not an exact duplicate, but definitely the same root issue. See also the src/components/DisplayMessageCorrect.vue example there. Maybe you can comment there to have all information in one place?

@dmke
Copy link
Author

dmke commented Oct 30, 2023

Sure, will do.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants