kibana/x-pack/packages
Anton Dosov fccfd4cf75
[react@18] Implicit children type fixes (#192011)
## Summary

Part of https://github.com/elastic/kibana/issues/138222

in @types/react@18 types [have become more
strict](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56210).
This PR addresses a bunch of easy fixes. The most common are:

### 1 Removal of implicit children

For components that do implement children but relied on their implicit
declaration from React.FunctionComponent or React.Component:

```diff
 interface Props {
+  children?: React.ReactNode;
 }

 class SomeClassComponents React.Component<Props> {
   render() {
     return  <div>{this.props.children}</div>
   }
 }
 const SomeFunctionComponent: React.FunctionComponent<Props> = props => <div>{props.children}</div>
```

or 

```diff
- const SomeFunctionComponent: React.FunctionComponent<Props> = props => <div>{props.children}</div>
+ const SomeFunctionComponent: React.FunctionComponent<React.PropsWithChildren<Props>> = props => <div>{props.children}</div>
```


*Note 1:*
The most common change occurs in unit tests where `renderHook` and
`wrapper` are used. I had to re-type the props so that `children` were
there

```diff
const { result } = renderHook(
         () => {
           return useLicense();
         },
         {
-           wrapper: ({ children }) => (
+           wrapper: ({ children }: React.PropsWithChildren<{}>) => (
             <TestProviders license={license}>{children}</TestProviders>
           ),
         }
       );
```

```diff
- const { result } = renderHook<GetCasesColumn, UseCasesColumnsReturnValue>(
+ const { result } = renderHook<React.PropsWithChildren<GetCasesColumn>, UseCasesColumnsReturnValue>(
       () => useCasesColumns(defaultColumnArgs),
       {
         wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
       }
     );
```



*Note 2:*
With @types/react@17 the components that don't have any props apart from
`children` I had to use `React.PropsWithChildren<{}>`, whereas in
@types/react@18 the argument becomes optional, so it can be omitted, and
type simpler with `React.PropsWithChildren` without an argument



### 2 `this.context` becomes `unknown` (was `any`)

In a couple of places where `this.context` is used, I had to type it

### 3 `ComponentType` from enzyme is no longer compatible with
`ComponentType` from react

This one is a bummer, but where `wrappingComponent` with enzyme is used
I had to cast it to type from `enzyme`

```diff
- import { mount } from 'enzyme'
+ import { mount, ComponentType } from 'enzyme'

 wrapper = mount(<ClosureOptions {...props} />, {
-       wrappingComponent: TestProviders,
+       wrappingComponent: TestProviders as ComponentType<{}>,
});
```
2024-09-09 13:56:02 +02:00
..
index-management Minimize shared-common everywhere (#188606) 2024-07-29 12:47:46 -06:00
kbn-alerting-comparators [OBS-UX-MNGMT] Move the Alerting comparators from TriggersActionsUI plugin to the alerting-types package (#181584) 2024-05-28 15:34:52 +02:00
kbn-alerting-state-types [Move @kbn/config-schema to server] @kbn/alerting-state-types (#191786) 2024-09-02 16:46:48 -05:00
kbn-cloud-security-posture [Cloud Security] Host Name Misconfiguration Datagrid & Refactor CSP Plugin PHASE 1 (#192114) 2024-09-06 12:42:55 -07:00
kbn-cloud-security-posture-common [Cloud Security] Support for missing fields in vulnerabilities and removing integration installation block (#191504) 2024-09-09 11:23:50 +02:00
kbn-data-forge Changing load/dump in source files (#190641) 2024-08-21 07:29:36 -04:00
kbn-elastic-assistant [react@18] Implicit children type fixes (#192011) 2024-09-09 13:56:02 +02:00
kbn-elastic-assistant-common Improves Security AI Assistant API docs content (#192254) 2024-09-06 18:11:47 +01:00
kbn-entities-schema [EEM] Migrate to using @kbn/server-route-repository (#191102) 2024-09-06 04:11:28 -05:00
kbn-infra-forge [Dev] Add High Cardinality Indexer to Kibana as kbn-data-forge (#174559) 2024-01-23 16:32:09 -07:00
kbn-langchain [Security Assistant] Fix langgraph issues (#189287) 2024-07-31 15:32:29 -05:00
kbn-random-sampling [ES|QL] Add line breaks redesign (#173596) 2023-12-21 11:01:15 +02:00
kbn-slo-schema feat(slo): group by instance id (#186131) 2024-06-19 09:04:48 -04:00
kbn-synthetics-private-location [Synthetics] add synthetics-private-location command (#189531) 2024-08-09 07:02:02 -04:00
maps/vector_tile_utils [maps] fix double encoding MVT request body (#157788) 2023-05-16 14:45:40 -06:00
ml [ML] Improving empty object creation in ML packages (#191901) 2024-09-03 10:08:21 +01:00
observability [Obs utils] Add Observability utils package (#189712) 2024-08-28 06:03:25 -05:00
rollup [Rollups] Update Rollup badge for deprecation (#186321) 2024-06-21 19:42:25 +01:00
security [react@18] Implicit children type fixes (#192011) 2024-09-09 13:56:02 +02:00
security-solution [react@18] Implicit children type fixes (#192011) 2024-09-09 13:56:02 +02:00