question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

arrow-parens crashes when parsing typescript function with generics

See original GitHub issue

Tell us about your environment

Node version: v10.15.3
npm version: v6.12.0
Local ESLint version: v6.6.0 (Currently used)

What parser (default, Babel-ESLint, etc.) are you using? @typescript-eslint/parser Please show your full configuration:

Configuration

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

const useABTests = <T extends ABTests, TName extends Extract<keyof T, string | number>>() => {
 ...
}

What did you expect to happen?

What actually happened? Please include the actual, raw output from ESLint. the arrow-parens rule for above code detects firstTokenOfParam as < and that is incorrect. As result of this, later on, when asserting the rule, it does:

!astUtils.isOpeningParenToken(firstTokenOfParam)
 // return token.value === "(" && token.type === "Punctuator";

and it marks the typescript code as breaking the rule settings, so it tries to log the error message, but it will fail, since getLocation helper always grabs starting location from params array that in this case is undefined, resulting in crash

TypeError: Cannot read property 'loc' of undefined

Are you willing to submit a pull request to fix this bug? Yeah, I’ve been looking at the code and with small guidance I could maybe do the fix

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
mdjermanoviccommented, Jun 26, 2020

I’ll work on this.

1reaction
kaicataldocommented, Nov 21, 2019

That’s great! You can find an example here. Please feel free to ask questions here or to stop by our Gitter chat.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript Playground Error on using generic type with Arrow ...
As I am new to generic types , I assume its not a bug with ts playground rather my lack of understanding. Also...
Read more >
Documentation - Generics - TypeScript
This allows us to traffic that type information in one side of the function and out the other. We say that this version...
Read more >
Understanding TypeScript Generics - Smashing Magazine
An introduction to the utilization of Generics in TypeScript with examples grounded ... Internally, the create method calls the constructor.
Read more >
Really Advanced Typescript Types - Tableau Engineering Blog
Functions returned by other functions need not be non-generic. In other words, functions may return generic functions:
Read more >
tslint: Versions - Openbase
[bugfix] add support for TypeScript 4.0 peer dependency (#4943) ... no longer crashes if it cannot find the closing parenthesis of a function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found