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

Parse error on generic arrow function #473

Closed
WhiteAbeLincoln opened this issue Apr 24, 2018 · 3 comments
Closed

Parse error on generic arrow function #473

WhiteAbeLincoln opened this issue Apr 24, 2018 · 3 comments
Labels

Comments

@WhiteAbeLincoln
Copy link

WhiteAbeLincoln commented Apr 24, 2018

What version of TypeScript are you using?
^2.8.3

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

What code were you trying to parse?

export const somes = <T>(options: ReadonlyArray<Option<T>>): ReadonlyArray<T> =>
  options.filter(isSome).map(o => o.value)

What did you expect to happen?
There not to be a parse error

What happened?
Eslint reported Parsing error: Identifier expected on Option<T>:

export const somes = <T>(options: ReadonlyArray<Option<T>>): ReadonlyArray<T> =>
                                                ^^^^^^^^^
  options.filter(isSome).map(o => o.value)

Changing this to a function statement instead of a arrow function removes the parse error.
These are both valid:

export const somes = function<T>(options: ReadonlyArray<Option<T>>): ReadonlyArray<T> {
  return options.filter(isSome).map(o => o.value)
}
export function somes<T>(options: ReadonlyArray<Option<T>>): ReadonlyArray<T> {
  return options.filter(isSome).map(o => o.value)
}

Additionally, removing the type from the parameter changes the error to JSX element 'T' has no corresponding closing tag on the return type ReadonlyArray<T>:

export const somes = <T>(options: Option<T>[]): ReadonlyArray<T> =>
                                                ^^^^^^^^^^^^^^ 
  options.filter(isSome).map(o => o.value)

This is not a .tsx file, so the parser should probably not be attempting to parse types as JSX tags

@gmathieu
Copy link

gmathieu commented May 9, 2018

I noticed the same error with the following:

import { getMiddleware } from 'lib/env'
import { createStore as reduxCreateStore, applyMiddleware, StoreCreator, Reducer } from 'redux'
import thunk from 'redux-thunk'

const storeCreator: StoreCreator = <S>(reducer: Reducer<S>) => {
    return reduxCreateStore(reducer, applyMiddleware(thunk, ...getMiddleware()))
}

export default storeCreator
lib/create-store.ts
  6:4  error  Parsing error: Expression expected

@JamesHenry
Copy link
Member

Does your configuration have jsx: true?

If so it is highly likely: #517

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

@JamesHenry
Copy link
Member

Hopefully this was covered by the resolution to #517, feel free to reopen if not!

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

No branches or pull requests

3 participants