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

Flow: Generic type parameters not supported on arrow functions #28

Closed
clark-pan opened this issue Apr 11, 2018 · 6 comments
Closed

Flow: Generic type parameters not supported on arrow functions #28

clark-pan opened this issue Apr 11, 2018 · 6 comments
Labels

Comments

@clark-pan
Copy link

I'm using version v1.1.0-alpha.2

Generic types for arrow functions don't seem to be working.

screen shot 2018-04-11 at 10 24 37 am

@Thom1729
Copy link
Owner

Thanks for the find.

I'll take a more detailed look at this, but this may be a case where we'll have to use an unreliable heuristic. It looks like you're using JSX as well, and <T> looks like a JSX tag. It is absolutely impossible for a sublime syntax to tell the difference in the general case. In fact, I'm not sure how this isn't a genuine grammatical ambiguity.

See this TypeScript issue, which is closed as a “Design Limitation”.

In the mean time, I'd suggest using function<> as a workaround.

@Thom1729 Thom1729 added the bug label Apr 11, 2018
@clark-pan
Copy link
Author

Thanks for looking into it. I'm not 100% familiar with how sublime syntax stuff works, but is there no way to capture the opening tag of jsx and only consider it jsx if theres a closing matching tag?

So a just on its own is considered flow type, but is actually what makes it JSX (or as well i guess)

@clark-pan
Copy link
Author

I've also worked around it by separating the definition of the type and the implementation:

type Foo<T: Object> = (a: T) => T
const foo:Foo<*> = (a) => {
  //...
}

@Thom1729 Thom1729 changed the title Generic type annontation for arrow functions Flow: Generic type parameters not supported on arrow functions May 9, 2018
@neutraali
Copy link

Don't know whether this is related to generic types, class properties or just angle bracket type definitions in particular, but:

export default class ExampleComponent extends React.Component<Props> {
	_iframe: React.Ref<typeof HTMLIFrameElement>
	// Syntax highlighting broken beyond this point

This happens with most angle-bracket stuff, for example Array<string>.

@Thom1729
Copy link
Owner

@neutraali I've just fixed this in 1.0.19. The problem was that typeof expected an expression, and so it parsed the > as a greater-than operator. I have modified the Flow extension so that typeof will expect a LeftExpression. Please let me know if that problem recurs.

@neutraali
Copy link

Thanks @Thom1729 👍 - Will do just as soon as you upload that to Package Control 😸

@Thom1729 Thom1729 closed this as completed Jan 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants