Skip to content

Generic parameter in arrow function in .tsx file causes an error #45589

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

Closed
danfma opened this issue Aug 26, 2021 · 2 comments
Closed

Generic parameter in arrow function in .tsx file causes an error #45589

danfma opened this issue Aug 26, 2021 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@danfma
Copy link

danfma commented Aug 26, 2021

Bug Report

πŸ”Ž Search Terms

typescript, generic, .tsx, react, function

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried from 4.0.5+.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

import React, { useCallback } from 'react';

function MyComponent() {
  // Using a simple hook to cause the problem (not a real code)

  // This works
  const promisify = useCallback(
    // NOTE Current TypeScript version doesn't support generic in arrow functions in TSX files
    function <R>(value: R): Promise<R> {
      return Promise.resolve(value);
    },
    []
  );

  // This does not work - it also happens when removing the useCallback and just defining a simple function too.
  const promisify2 = useCallback(
    // NOTE Current TypeScript version doesn't support generic in arrow functions in TSX files
    <R>(value: R): Promise<R> => {
      return Promise.resolve(value);
    },
    []
  );

  return null;
}

πŸ™ Actual behavior

The compiler doesn't recognize the generic parameter when using an arrow function in a .tsx file and gives an error like if you are using a JSX element as a function.

πŸ™‚ Expected behavior

I should be able to define generic arrow functions in .tsx files too (I guess ;) ).

@MartinJohns
Copy link
Contributor

Duplicate of #15713.

@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Aug 27, 2021
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants