babel / babel-eslint

:tokyo_tower: A wrapper for Babel's parser used for ESLint (renamed to @babel/eslint-parser)
https://github.com/babel/babel/tree/main/eslint/babel-eslint-parser
MIT License
2.96k stars 208 forks source link

Error on 'extends' operator on generic type #841

Closed HyunnoH closed 4 years ago

HyunnoH commented 4 years ago

I uses Storybook.js on my work, and Storybook.js puts an error when compiling my type definition.

ERROR in ../libs/shared/src/utils/types.ts
Module Error (from /Users/hyun/workspace/yennefer-suite/node_modules/eslint-loader/dist/cjs.js):

  Line 1:23:  Parsing error: Unexpected token, expected ","

> 1 | export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
    |                       ^
  2 | 
  3 | export type Partial<T> = { [P in keyof T]?: T[P] };
  4 | 

Here is my eslintrc setup.

{
  "parser": "@typescript-eslint/parser", // Specifies the ESLint parser
  "extends": [
    "plugin:react/recommended", // Uses the recommended rules from @eslint-plugin-react
    "plugin:@typescript-eslint/recommended", // Uses the recommended rules from @typescript-eslint/eslint-plugin
    "plugin:import/errors",
    "plugin:import/warnings",
    "airbnb",
    "prettier"
  ],
  "parserOptions": {
    "ecmaVersion": 2018, // Allows for the parsing of modern ECMAScript features
    "sourceType": "module", // Allows for the use of imports
    "ecmaFeatures": {
      "jsx": true // Allows for the parsing of JSX
    }
  },
  // plugins:
  "rules": {
    // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
    "@typescript-eslint/explicit-function-return-type": "off",
    "import/order": [
      "error",
      {
        "pathGroups": [
          {
            "pattern": "@project/shared",
            "group": "internal",
            "position": "after"
          }
        ],
        "newlines-between": "always"
      }
    ],
    "import/no-unresolved": 0,
    "import/extensions": 0,
    "react/jsx-filename-extension": 0,
    "no-undef": 0,
    "react/jsx-props-no-spreading": 0,
    "react/jsx-curly-newline": 0,
    "react/jsx-one-expression-per-line": 0,
    "react/jsx-wrap-multilines": ["error", { "declaration": false, "assignment": false }]
  },
  "settings": {
    "react": {
      "version": "detect" // Tells eslint-plugin-react to automatically detect the version of React to use
    }
  }
}

And this is my webpack config.

{
        test: /\.(ts|tsx)$/,
        include: path.resolve(__dirname, path.resolve('@project/shared/src')),
        use: [
          require.resolve('ts-loader'),
          {
            loader: require.resolve('react-docgen-typescript-loader'),
            options: {
              // Provide the path to your tsconfig.json so that your stories can
              // display types from outside each individual story.
              tsconfigPath: path.resolve(__dirname, './tsconfig.json'),
            },
          },
        ],
      },

This issues is already reported on #782 , but I don't know is this already solved on latest version. Can you let me know about this?

JLHwung commented 4 years ago

@HyunnoH Thanks for the report. As is shown in the config your projects uses @typescript-eslint/parser, please submit an issue there https://github.com/typescript-eslint/typescript-eslint