Skip to content

Commit

Permalink
[Shared UX] Clean up after TS upgrade (#179588)
Browse files Browse the repository at this point in the history
## Summary

Closes #176113

---------

Co-authored-by: Sébastien Loix <sebastien.loix@elastic.co>
  • Loading branch information
tsullivan and sebelga authored Apr 1, 2024
1 parent d041955 commit 5c25069
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
22 changes: 15 additions & 7 deletions packages/shared-ux/router/impl/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ import { Switch, useRouteMatch } from 'react-router-dom';
import { Routes as ReactRouterRoutes, Route } from 'react-router-dom-v5-compat';
import { Route as LegacyRoute, MatchPropagator } from './route';

type RouterElementChildren = Array<
React.ReactElement<
{
path: string;
render: Function;
children: RouterElementChildren;
component: Function;
},
string | React.JSXElementConstructor<unknown>
>
>;

export const Routes = ({
legacySwitch = true,
children,
Expand All @@ -26,24 +38,20 @@ export const Routes = ({
<Switch>{children}</Switch>
) : (
<ReactRouterRoutes>
{Children.map(children, (child) => {
{Children.map(children as RouterElementChildren, (child) => {
if (React.isValidElement(child) && child.type === LegacyRoute) {
const path = replace(child?.props.path, match.url + '/', '');
const renderFunction =
// @ts-expect-error upgrade typescript v4.9.5
typeof child?.props.children === 'function'
? // @ts-expect-error upgrade typescript v4.9.5
child?.props.children
: // @ts-expect-error upgrade typescript v4.9.5
child?.props.render;
? child?.props.children
: child?.props.render;

return (
<Route
path={path}
element={
<>
<MatchPropagator />
{/* @ts-expect-error upgrade typescript v4.9.5*/}
{(child?.props?.component && <child.props.component />) ||
(renderFunction && renderFunction()) ||
children}
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/files/server/routes/file_kind/enhance_router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export function enhanceRouter({ router, fileKind }: Args): FileKindRouter {
const handlerWrapper: (handler: FileKindHandler) => FileKindHandler =
(handler) => async (ctx, req, res) => {
return handler(
// @ts-expect-error upgrade typescript v4.9.5
Object.create(ctx, { fileKind: { value: fileKind, enumerable: true, writeable: false } }),
Object.create(ctx, { fileKind: { value: fileKind, enumerable: true, writable: false } }),
req,
res
);
Expand Down
15 changes: 9 additions & 6 deletions src/plugins/files/server/routes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
*/

import type {
RequestHandlerContext,
HttpResponsePayload,
IKibanaResponse,
IRouter,
RequestHandler,
RouteMethod,
KibanaResponseFactory,
IKibanaResponse,
Logger,
RequestHandler,
RequestHandlerContext,
ResponseError,
RouteMethod,
} from '@kbn/core/server';
import type { SecurityPluginStart } from '@kbn/security-plugin/server';
import type { FileServiceStart } from '../file_service';
Expand Down Expand Up @@ -41,8 +43,9 @@ export type FilesRequestHandler<
Method extends RouteMethod = any
> = RequestHandler<P, Q, B, FilesRequestHandlerContext, Method, KibanaResponseFactory>;

// @ts-expect-error upgrade typescript v4.9.5
export type AsyncResponse<T> = Promise<IKibanaResponse<T>>;
export type AsyncResponse<T extends HttpResponsePayload | ResponseError = any> = Promise<
IKibanaResponse<T>
>;

export type CreateHandler<E extends AnyEndpoint> = FilesRequestHandler<
E['inputs']['params'],
Expand Down

0 comments on commit 5c25069

Please sign in to comment.