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

Syntax for specialized calls of generic constructors and functions #14

Open
samwgoldman opened this issue Jul 19, 2017 · 0 comments
Open

Comments

@samwgoldman
Copy link

Given a type system with generics+inference+union types, it's useful to be able to instantiate the type parameters at a call site.

For example, a function with two generic arguments T might be inferred as a union of two unrelated types if called without a specific instantiation.

function f<T>(a: T, b: T): { x: T, y: T } {
  return { x: a, y: b };
}

var result: { x: number|string, y: number|string } = f(0, "");

One option would be to prevent inference of a union here, but I am not interested in semantics here. Rather, I am interested in a parsing issue.

f<T>(x) is currently a valid program in JS. Specifically, it's a nested binary expression ((f<T)>x), which is a fairly useless parse tree IMO, but a parse tree nonetheless.

Note that TypeScript interprets f<T>(x) as a call expression, departing from JS in this small way. Flow has held off on this feature, due to the parser ambiguity, but we would very much like to support this use case.

Ref #6

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

No branches or pull requests

1 participant