Skip to content

[@types/react] Discrepancy between JSX props and the values for those props (for function props) #50459

Open

Description

@smirea

Is something wrong with CI or publishing infrastructure? --> no

If you know how to fix the issue, make a pull request instead.

If you do not mention the authors the issue will be ignored.


React version: 16.13.1 (also tried on 17 latest)
Typescript version: 4.1.2

Steps To Reproduce

See the code examples bellow

  1. Create a component that compiles its props based on the props of a child
  2. Pass a child with a primitive type and a callback type prop
  3. Observe that the primitive type is inferred correctly but the callback prop is not

The motivation for this was to create a Wrapper component that inherits all the props from a given child component

JSX prop type detected successfully The value of that same prop erros with "no implicit any"
Screen Shot 2021-01-03 at 12 48 27 PM Screen Shot 2021-01-03 at 12 51 50 PM

These examples are from https://www.typescriptlang.org/play but I get the same behavior when using local tsc compiling

Link to code example:

  • TypeScript issue example Line 19 is the problem, the callback property gets the correct type if you hover over the JSX prop name, but TS complains that val is implicit any

  • An equivalent plain TS example without react I did my best to reproduce the behavior in pure typescript to make sure this is specifically a react problem and not a TS problem.

The current behavior

Inferred callback props cause TS errors, even though they are detected properly in the JSX attributes

The expected behavior

Consistent type definitions between JSX props and the value of those props

Activity

  1. dimitropoulos commented on Apr 5, 2021

    @dimitropoulos
    Contributor

    I would love this to be solved and it would help a lot of people, but I have yet to see an implementation that solves it. Do you have one in mind? @eps1lon any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions