Skip to content

vue/valid-define-emits and -props treat types as local variable and fail #1656

Closed
@larvanitis

Description

@larvanitis

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: 7.32.0
  • eslint-plugin-vue version: 7.19.1
  • Node version: 14.17.4
  • Operating System: Arch Linux

Please show your full configuration:

module.exports = {
  root: true,

  parserOptions: {
    extraFileExtensions: ['.vue'],
    parser: '@typescript-eslint/parser',
    project: './tsconfig.json',
    tsconfigRootDir: __dirname,
    ecmaVersion: 2018,
    sourceType: 'module',
  },

  env: {
    browser: true,
  },

  extends: [
    'plugin:vue/vue3-essential',
  ],

  plugins: [
    '@typescript-eslint',
    'vue',
  ],

  rules: {
    'vue/valid-define-emits': 'error',
    'vue/valid-define-props': 'error',
  },
};

What did you do?

<script setup lang="ts">
import type { PropType } from 'vue';

const props = defineProps({
  myProp: Array as PropType<string[]>,
});             // ^ error


type X = string;

const emit = defineEmits({
  myEvent: (x: X) => true,
});         // ^ error
</script>

What did you expect to happen?
Use types without error.

What actually happened?

/path/to/Component.vue
   7:20  error  `defineProps` are referencing locally declared variables  vue/valid-define-props
  11:15  error  `defineEmits` are referencing locally declared variables  vue/valid-define-emits

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions