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

ESLint Error with Vue 3.3+ Alternative Syntax for TypeScript Emits Despite Support #2281

Closed
2 tasks done
BenJackGill opened this issue Aug 29, 2023 · 2 comments
Closed
2 tasks done

Comments

@BenJackGill
Copy link

BenJackGill commented Aug 29, 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: 8.48.0
  • eslint-plugin-vue version: 9.17.0
  • Node version: 18.17.0
  • Operating System: MacOs Ventura 13.4.1 (c)

Please show your full configuration:

module.exports = {
  // https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser
  // Must use parserOptions instead of "parser" to allow vue-eslint-parser to keep working
  // `parser: 'vue-eslint-parser'` is already included with any 'plugin:vue/**' config and should be omitted
  parserOptions: {
    parser: require.resolve("@typescript-eslint/parser"),
    extraFileExtensions: [".vue"],
  },
  // parser: "@typescript-eslint/parser",
  // parserOptions: {
  //   project: ["tsconfig.json", "tsconfig.dev.json"],
  //   sourceType: "module",
  // },

  env: {
    es6: true,
    node: true,
    browser: true,
    es2021: true,
    "vue/setup-compiler-macros": true,
  },

  extends: [
    // FUCNTIONS
    // "plugin:import/errors",
    // "plugin:import/warnings",
    // "plugin:import/typescript",

    // Turborepo rules, provided by 'eslint-config-turbo'.
    "turbo",

    // Google rules, provided by 'eslint-config-google'.
    "google",

    // Base ESLint recommended rules
    "eslint:recommended",

    // https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#usage
    // ESLint typescript rules
    "plugin:@typescript-eslint/recommended",

    // See https://eslint.vuejs.org/rules/#available-rules
    "plugin:vue/vue3-recommended",

    // https://github.com/prettier/eslint-config-prettier#installation
    // usage with Prettier, provided by 'eslint-config-prettier'.
    "prettier",
  ],

  ignorePatterns: [
    "/lib/**/*", // Ignore built files.
  ],

  plugins: [
    // required to apply rules which need type information
    "@typescript-eslint",

    // https://eslint.vuejs.org/user-guide/#why-doesn-t-it-work-on-vue-files
    // required to lint *.vue files
    "vue",

    // https://github.com/typescript-eslint/typescript-eslint/issues/389#issuecomment-509292674
    // Prettier has not been included as plugin to avoid performance impact
    // add it as an extension for your IDE

    // required to apply 'import/no-extraneous-dependencies' in rules
    "import",
  ],

  // Taken from Quasar eslint setup
  globals: {
    ga: "readonly", // Google Analytics
    google: "readonly", // Google Maps / Google Places
    cordova: "readonly",
    __statics: "readonly",
    __QUASAR_SSR__: "readonly",
    __QUASAR_SSR_SERVER__: "readonly",
    __QUASAR_SSR_CLIENT__: "readonly",
    __QUASAR_SSR_PWA__: "readonly",
    process: "readonly",
    Capacitor: "readonly",
    chrome: "readonly",
  },

  rules: {
    // Defines how to handle quotes
    quotes: ["warn", "double", { avoidEscape: true }],

    // Stops importing of packages that are not found in packages.json
    // "import/no-extraneous-dependencies": ["error", { packageDir: __dirname }],
    "import/no-extraneous-dependencies": ["error"],

    // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-unresolved.md
    // NOTE: MIGHT CAUSE ISSUES WITH VITE
    "import/no-unresolved": 0,

    // allow debugger during development only
    "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",

    // OTHER QUASAR ESLINT RULES - TEST TURNING OFF AND THEN DELETE ALTOGTHER:
    "prefer-promise-reject-errors": "off",
    // The core 'no-unused-vars' rules (in the eslint:recommended ruleset)
    // does not work with type definitions
    "no-unused-vars": "off",

    // this rule, if on, would require explicit return type on the `render` function
    "@typescript-eslint/explicit-function-return-type": "off",

    // in plain CommonJS modules, you can't use `import foo = require('foo')` to pass this rule, so it has to be disabled
    "@typescript-eslint/no-var-requires": "off",

    "valid-jsdoc": "off",
    "require-jsdoc": "off",
  },
};

What did you do?
I have a TurboRepo monorepo setup with eslint as per this doc.

And I am trying to use the new Vue 3.3+ alternative syntax to define TypeScript emits, as shown below:

// Here I am using the Vue 3.3+ alternative syntax to define TypeScript emits
const emit = defineEmits<{
  dateChange: [from: Date, to: Date];
}>();

emit("dateChange", new Date(), new Date()); // Error shows here

What did you expect to happen?
No error should be showing because support for version 3.3 syntax was already added.

What actually happened?
I get this ESLint error message:

The "dateChange" event has been triggered but not declared on `defineEmits`.eslint [vue/require-explicit-emits](https://eslint.vuejs.org/rules/require-explicit-emits.html)

Repository to reproduce this issue
https://github.com/BenJackGill/eslint-require-explicit-emits

@ota-meshi
Copy link
Member

I checked your repository and it looks like you are using v8. Please use the latest version.

@BenJackGill
Copy link
Author

BenJackGill commented Aug 29, 2023

I mistakenly uploaded the incorrect example repository. Even updating to the latest version didn't resolve the issue.

However, I found a solution:

  1. I created a duplicate of the monorepo.
  2. Gradually, I deleted content, ran npm install, and then refreshed Visual Studio Code after each deletion.
  3. By doing this, I isolated the issue to another app in the monorepo. Specifically, the problem was tied to a Firebase functions folder. Once this folder was removed, the eslint issue in a different app was fixed.

What ultimately resolved the issue was:

  1. Deleting all dependencies and devDependencies of the problematic app from package.json.
  2. Running npm install from the root.
  3. Re-adding all the dependencies back into package.json and then running npm install from the root once more. It's puzzling why this solution worked, especially since simply removing all node_modules and running npm install from the root hadn’t worked before.

I hope this information assists others facing a similar issue.

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

No branches or pull requests

2 participants