diff --git a/packages/core-api/src/app/App.test.tsx b/packages/core-api/src/app/App.test.tsx
index 7ab4928abf..4050343bbf 100644
--- a/packages/core-api/src/app/App.test.tsx
+++ b/packages/core-api/src/app/App.test.tsx
@@ -17,7 +17,7 @@
import { renderWithEffects, withLogCollector } from '@backstage/test-utils';
import { lightTheme } from '@backstage/theme';
import { render, screen } from '@testing-library/react';
-import React from 'react';
+import React, { PropsWithChildren } from 'react';
import { BrowserRouter, Routes } from 'react-router-dom';
import { createRoutableExtension } from '../extensions';
import { defaultSystemIcons } from '../icons';
@@ -66,14 +66,14 @@ describe('Integration Test', () => {
const HiddenComponent = plugin2.provide(
createRoutableExtension({
- component: () => null,
+ component: (_: { path?: string }) =>
,
mountPoint: plugin2RouteRef,
}),
);
const ExposedComponent = plugin1.provide(
createRoutableExtension({
- component: () => {
+ component: (_: PropsWithChildren<{ path?: string }>) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const routeRefFunction = useRouteRef(externalRouteRef);
return Our Route Is: {routeRefFunction({})}
;
diff --git a/packages/core-api/src/extensions/extensions.test.tsx b/packages/core-api/src/extensions/extensions.test.tsx
index 92fcecebc4..861045fb3d 100644
--- a/packages/core-api/src/extensions/extensions.test.tsx
+++ b/packages/core-api/src/extensions/extensions.test.tsx
@@ -30,7 +30,7 @@ const plugin = createPlugin({
describe('extensions', () => {
it('should create a react extension with component data', () => {
- const Component = () => null;
+ const Component = () => ;
const extension = createReactExtension({
component: Component,
@@ -47,7 +47,7 @@ describe('extensions', () => {
});
it('should create react extensions of different types', () => {
- const Component = () => null;
+ const Component = () => ;
const routeRef = createRouteRef({ path: '/foo', title: 'Foo' });
const extension1 = createComponentExtension({
diff --git a/packages/core-api/src/extensions/extensions.tsx b/packages/core-api/src/extensions/extensions.tsx
index 079fec4597..aca29e87dc 100644
--- a/packages/core-api/src/extensions/extensions.tsx
+++ b/packages/core-api/src/extensions/extensions.tsx
@@ -14,24 +14,14 @@
* limitations under the License.
*/
-import React, {
- NamedExoticComponent,
- ComponentType,
- PropsWithChildren,
-} from 'react';
+import React from 'react';
import { RouteRef } from '../routing';
import { attachComponentData } from './componentData';
import { Extension, BackstagePlugin } from '../plugin/types';
-export function createRoutableExtension(options: {
- component: ComponentType;
- mountPoint: RouteRef;
- // TODO(Rugvip): We want to carry forward the exact props type from the inner component, with
- // or without children. ComponentType stops us from doing that though, as it always
- // adds children to the props internally. We may want to work around this with custom types.
-}): Extension<
- NamedExoticComponent>
-> {
+export function createRoutableExtension<
+ T extends (props: any) => JSX.Element
+>(options: { component: T; mountPoint: RouteRef }): Extension {
const { component, mountPoint } = options;
return createReactExtension({
component,
@@ -41,21 +31,24 @@ export function createRoutableExtension(options: {
});
}
-export function createComponentExtension(options: {
- component: ComponentType;
-}): Extension> {
+export function createComponentExtension<
+ T extends (props: any) => JSX.Element
+>(options: { component: T }): Extension {
const { component } = options;
return createReactExtension({ component });
}
-export function createReactExtension(options: {
- component: ComponentType;
- data?: Record;
-}): Extension> {
- const { component: Component, data = {} } = options;
+export function createReactExtension<
+ T extends (props: any) => JSX.Element
+>(options: { component: T; data?: Record }): Extension {
+ const { data = {} } = options;
+ const Component = options.component as T & {
+ displayName?: string;
+ };
+
return {
- expose(plugin: BackstagePlugin): NamedExoticComponent {
- const Result = (props: Props) => ;
+ expose(plugin: BackstagePlugin) {
+ const Result: any = (props: any) => ;
attachComponentData(Result, 'core.plugin', plugin);
for (const [key, value] of Object.entries(data)) {
@@ -66,7 +59,7 @@ export function createReactExtension(options: {
if (name) {
Result.displayName = `Extension(${name})`;
}
- return Result as NamedExoticComponent;
+ return Result;
},
};
}
diff --git a/packages/core-api/src/plugin/collectors.test.tsx b/packages/core-api/src/plugin/collectors.test.tsx
index f040cfd433..e5f8a123e3 100644
--- a/packages/core-api/src/plugin/collectors.test.tsx
+++ b/packages/core-api/src/plugin/collectors.test.tsx
@@ -30,7 +30,9 @@ import {
import { pluginCollector } from './collectors';
const mockConfig = () => ({ path: '/foo', title: 'Foo' });
-const MockComponent = ({ children }: PropsWithChildren<{}>) => <>{children}>;
+const MockComponent = ({ children }: PropsWithChildren<{ path?: string }>) => (
+ <>{children}>
+);
const pluginA = createPlugin({ id: 'my-plugin-a' });
const pluginB = createPlugin({ id: 'my-plugin-b' });
diff --git a/packages/core-api/src/routing/collectors.test.tsx b/packages/core-api/src/routing/collectors.test.tsx
index 2595b8c0a0..e44474565c 100644
--- a/packages/core-api/src/routing/collectors.test.tsx
+++ b/packages/core-api/src/routing/collectors.test.tsx
@@ -28,7 +28,9 @@ import { createRoutableExtension } from '../extensions';
import { MemoryRouter, Routes, Route } from 'react-router-dom';
const mockConfig = () => ({ path: '/foo', title: 'Foo' });
-const MockComponent = ({ children }: PropsWithChildren<{}>) => <>{children}>;
+const MockComponent = ({ children }: PropsWithChildren<{ path?: string }>) => (
+ <>{children}>
+);
const plugin = createPlugin({ id: 'my-plugin' });
diff --git a/packages/core-api/src/routing/hooks.test.tsx b/packages/core-api/src/routing/hooks.test.tsx
index 6bc80b7c08..a29e263e14 100644
--- a/packages/core-api/src/routing/hooks.test.tsx
+++ b/packages/core-api/src/routing/hooks.test.tsx
@@ -47,7 +47,9 @@ const mockConfig = (extra?: Partial>) => ({
title: 'Unused',
...extra,
});
-const MockComponent = ({ children }: PropsWithChildren<{}>) => <>{children}>;
+const MockComponent = ({ children }: PropsWithChildren<{ path?: string }>) => (
+ <>{children}>
+);
const plugin = createPlugin({ id: 'my-plugin' });
@@ -61,6 +63,7 @@ const eRefB = createExternalRouteRef();
const eRefC = createExternalRouteRef();
const MockRouteSource = (props: {
+ path?: string;
name: string;
routeRef: RouteRef | ExternalRouteRef;
params?: T;