vuejs / eslint-plugin-vue

Official ESLint plugin for Vue.js
https://eslint.vuejs.org/
MIT License
4.46k stars 666 forks source link

`vue/require-valid-default-prop` false-positive when using TS prop definition #1853

Closed schw4rzlicht closed 2 years ago

schw4rzlicht commented 2 years ago

Checklist

Tell us about your environment

Please show your full configuration:

require("@rushstack/eslint-patch/modern-module-resolution");

module.exports = {
    root: true,
    extends: [
        "plugin:eslint-comments/recommended",
        "plugin:vue/vue3-strongly-recommended",
        "plugin:vue/vue3-recommended",
        "airbnb-typescript/base",
        "@vue/typescript/recommended",
        "@vue/prettier",
        "plugin:storybook/recommended",
        "plugin:markdown/recommended",
        "prettier",
    ],
    plugins: ["import"],
    parserOptions: {
        ecmaVersion: 2020,
        project: ["./tsconfig.json", "./tsconfig.vite-config.json"],
    },
    settings: {
        "import/parsers": {
            "@typescript-eslint/parser": [".ts", ".tsx"],
        },
    },
    env: {
        node: true,
        es2021: true,
        "vue/setup-compiler-macros": true,
    },
    rules: {
        "@typescript-eslint/quotes": ["error", "double", { allowTemplateLiterals: true, avoidEscape: true }],
        "max-len": ["error", 200, 4],
        "no-param-reassign": "off",
        "no-use-before-define": "off",
        "no-console": "error",
        "no-debugger": "error",
        "no-plusplus": "off",
        "@typescript-eslint/no-unused-vars": "error",
        "eslint-comments/disable-enable-pair": ["error", { allowWholeFile: true }],
        "vue/no-v-html": "error",
    },
    overrides: [
        {
            files: ["vite.config.ts", "tailwind.config.js"],
            rules: {
                "import/no-extraneous-dependencies": "off",
            },
        },
    ],
};

What did you do?

export interface SomePropInterface {
  someProp?: false | string;
}

withDefaults(defineProps<SomePropInterface>(), {
  someProp: false,
});

What did you expect to happen?

Assigning false to someProp as default value should be okay.

What actually happened?

ESLint: Type of the default value for 'someProp' prop must be a string.(vue/require-valid-default-prop)

Repository to reproduce this issue

I don't really think it's necessary but I will take the time to create one if really needed.

ota-meshi commented 2 years ago

Thank you for the bug report. I started to fix it.