Search code examples
reactjstypescripttypescript-typingstypescript-generics

Issue with type of Custom Select Component: Error When Using Generic Type <T,> with Comma vs. <T> Without Comma


I have created a custom select component that extends the HTML select element. I utilized a generic type to accommodate various data types, and I came across an unusual error. The error persists when I use <T,> with a comma, as shown here.

with comma

However, if i remove the comma, changing <T,> to , an error occurs everywhere, as shown here.

without comma

What causes this problem ?


Solution

  • there is nothing wrong with your code, whether with the comma or without

    the comma in the generics is needed because otherwise there would be a collapse of 2 identical syntaxes in the tsx files

    therefore, as a compromise, when you make a component that accepts only one generic, put the comma to make the parser understand that it is a generic and not a component