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

@types/react - Invalid definition of children #49876

Closed
5 tasks done
michalbundyra opened this issue Nov 30, 2020 · 7 comments
Closed
5 tasks done

@types/react - Invalid definition of children #49876

michalbundyra opened this issue Nov 30, 2020 · 7 comments

Comments

@michalbundyra
Copy link

Is something wrong with CI or publishing infrastructure?

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

The original issue report is here: mui/material-ui#23792

I've been told there that the issue is not with TypeScript nor Material-UI but the problem is in @types/react that's why I am creating that issue. To be completely honest I did not even suspect that and I have no idea how to fix it. I just know that my code does not work when I try latest stable TypeScript (4.1.2).

Errors I am getting are as follows:

Type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)> | ReactElement<...>[]' is not assignable to type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)>'.
  Type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)>[]' is missing the following properties from type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)>': type, props, key(2322)
@eps1lon
Copy link
Collaborator

eps1lon commented Dec 1, 2020

The part that @types/react is not correctly implementing:

React.Children.map could narrow the item a bit but that's an issue for @types/react

In React.Children.map(children, mappingFunction) mappingFunction is only invoked with null | ReactElement | number | string. React.Children.map flattens arrays.

Runtime semantics: https://codesandbox.io/s/reactchildrenmap-semantics-jv0pz
Expected types behavior: https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQNwBQduEAdqvLgBbAA2AJpczgBeOAG0Ars15YCwZll4AaOM3Hduygsm6osymFHF6xAXWWiAjGbgAeXsABucAPQA+E-TrY8MAHQBhLj4BXxBkMAAKTh5+LGZlKKDeAC4VNW44AB80kAAjLCgszCo-b3wAUW4sEDiYAEphVzgAbwBfOqA

@michalbundyra
Copy link
Author

@eps1lon thanks for your response. Is there any way we can easily fix it? Thanks

@eps1lon
Copy link
Collaborator

eps1lon commented Dec 2, 2020

We would need to update the typings.

@michalbundyra
Copy link
Author

@eps1lon not sure if I understand... so the problem is not on @types/react but in my code?
I am not sure what I should change, as it was working on TypeScript < 4.1... Thanks

@eps1lon
Copy link
Collaborator

eps1lon commented Dec 2, 2020

@eps1lon not sure if I understand... so the problem is not on @types/react but in my code?

The problem is in @types/react. I was referring to the typings of @types/react which need to be updated.

@michalbundyra
Copy link
Author

I've tried several different combinations on:

map<T, C>(children: C | C[], fn: (child: C, index: number) => T):
C extends null | undefined ? C : Array<Exclude<T, boolean | null | undefined>>;

but honestly I have no idea how to fix it in the correct way... 😕

@orta
Copy link
Collaborator

orta commented Jun 7, 2021

Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the @types modules in DefinitelyTyped.

To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the definitely-typed channel.

@orta orta closed this as completed Jun 7, 2021
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

3 participants