Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Generic type on a method is throwing a parsing error #497

Closed
Kocal opened this issue Jul 14, 2018 · 3 comments
Closed

Generic type on a method is throwing a parsing error #497

Kocal opened this issue Jul 14, 2018 · 3 comments
Labels

Comments

@Kocal
Copy link

Kocal commented Jul 14, 2018

Hello,

I'm migrating my code base to the new vue-cli tooling, and I encountered an issue when running ESLint on TypeScript code that use a generic type. 😞

If it can help, I'm using @vue/cli-plugin-eslint and @vue/eslint-config-typescript.
Here is my .eslintrc.js:

module.exports = {
  root: true,
  env: {
    node: true
  },
  'extends': [
    'plugin:vue/recommended',
    '@vue/prettier',
    '@vue/typescript',
  ],
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'on' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'on' : 'off',
  }
};

What version of TypeScript are you using?

Version 2.9.2 and 3+

What version of typescript-eslint-parser are you using?

Version 16.0.1

What code were you trying to parse?

export const decorateRequest = <T>(request: Promise<T>, bag: RequestBag): Promise<T> => {
  Object.assign(bag, makeRequestBag());

  return new Promise<T>(resolve => {
    // ...
  });
};

What did you expect to happen?

No errors

capture d ecran de 2018-07-14 21-47-37

For having this result, I changed my code to:

-export const decorateRequest = <T>(request: Promise<T>, bag: RequestBag): Promise<T> => {
+export const decorateRequest = (request: Promise<any>, bag: RequestBag): Promise<any> => {
  Object.assign(bag, makeRequestBag());

  return new Promise<T>(resolve => {
    // ...
  });
};

What happened?

capture d ecran de 2018-07-14 21-45-38

When using AST explorer with typescript-eslint-parser, my code is not parsed: https://astexplorer.net/#/gist/c19d736c02a606dc437892e2ba502ab6/2cf1e76e411f75f6aa7c94328724b8e7fa504611

capture d ecran de 2018-07-14 21-57-41

But when I change to typescript, it's working: http://astexplorer.net/#/gist/c19d736c02a606dc437892e2ba502ab6/fde12f491295d79d28c9d05e02486734932fb3a0

Tell me if you need more info, I will be glad to help you to solve this bug 👍
Thanks

@GuoQichen
Copy link

GuoQichen commented Sep 21, 2018

same problem with vue-cli3

const echo = <T>(arg: T): T => {
    let a = 1
    return arg
}

image

@JamesHenry
Copy link
Member

JamesHenry commented Sep 25, 2018

Is one or more of those configs being extended setting jsx: true?

If so it is highly likely: #517

You can reproduce the same behaviour with the TypeScript parser directly on https://astexplorer.net/

@mysticatea
Copy link
Member

Closing as favor of #517. Thank you.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants