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

Generic arrow functions and JSX #4922

Closed
shadeglare opened this issue Sep 22, 2015 · 2 comments
Closed

Generic arrow functions and JSX #4922

shadeglare opened this issue Sep 22, 2015 · 2 comments
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead Canonical This issue contains a lengthy and complete description of a particular problem, solution, or design

Comments

@shadeglare
Copy link

Typescript introduces support for the JSX syntax. So I have an expression that works quite well with traditional *.ts files but no with *.tsx ones:

const f = <T1>(arg1: T1) => <T2>(arg2: T2) => {
   return { arg1, arg2 };
}
@danquirk
Copy link
Member

This is an unfortunate side effect of syntax ambiguities. You need to either have an extends clause or multiple type parameters. You can write an extends clause that is functionally equivalent (albeit annoying):

const f = <T1 extends {}>(arg1: T1) => <T2 extends {}>(arg2: T2) => {
   return { arg1, arg2 };
}

@danquirk danquirk changed the title Typescript TSX and generic parameters Generic arrow functions and JSX Sep 22, 2015
@danquirk danquirk added By Design Deprecated - use "Working as Intended" or "Design Limitation" instead Canonical This issue contains a lengthy and complete description of a particular problem, solution, or design labels Sep 22, 2015
@shogowada
Copy link

That almost worked for me.

To cover all the types including null, I believe it technically should extend any:

const f = <T1 extends any>(arg1: T1) => <T2 extends any>(arg2: T2) => {
   return { arg1, arg2 };
}

I think it better communicates that it's no-op too, while extending {} can look like it is a real restriction it wants to enforce.

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead Canonical This issue contains a lengthy and complete description of a particular problem, solution, or design
Projects
None yet
Development

No branches or pull requests

3 participants