frontend-test-utils: fix TestApiPair type inference for tuple syntax

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2026-02-27 21:13:25 +01:00
parent a39b080302
commit 479282f38e
7 changed files with 12 additions and 11 deletions
@@ -0,0 +1,5 @@
---
'@backstage/frontend-test-utils': patch
---
Fixed type inference of `TestApiPair` when using tuple syntax by wrapping `MockWithApiFactory` in `NoInfer`.
@@ -1,5 +0,0 @@
---
'@backstage/test-utils': patch
---
Added `const` type parameter modifier to `TestApiProvider` and `TestApiRegistry.from` for improved type inference of API pairs.
+1
View File
@@ -0,0 +1 @@
Fixed a type inference issue with the `apis` option of testing utilities in `@backstage/frontend-test-utils`.
+1 -1
View File
@@ -443,7 +443,7 @@ export type RenderTestAppOptions<TApiPairs extends any[] = any[]> = {
// @public
export type TestApiPair<TApi> =
| readonly [ApiRef<TApi>, TApi extends infer TImpl ? Partial<TImpl> : never]
| MockWithApiFactory<TApi>;
| MockWithApiFactory<NoInfer<TApi>>;
// @public
export type TestApiPairs<TApiPairs> = {
@@ -29,7 +29,7 @@ import {
*/
export type TestApiPair<TApi> =
| readonly [ApiRef<TApi>, TApi extends infer TImpl ? Partial<TImpl> : never]
| MockWithApiFactory<TApi>;
| MockWithApiFactory<NoInfer<TApi>>;
/**
* Represents an array of mock API implementation.
+2 -2
View File
@@ -340,7 +340,7 @@ export function setupRequestMockHandlers(worker: {
export type SyncLogCollector = () => void;
// @public
export const TestApiProvider: <const T extends any[]>(
export const TestApiProvider: <T extends any[]>(
props: TestApiProviderProps<T>,
) => JSX_2.Element;
@@ -352,7 +352,7 @@ export type TestApiProviderProps<TApiPairs extends any[]> = {
// @public
export class TestApiRegistry implements ApiHolder {
static from<const TApiPairs extends any[]>(
static from<TApiPairs extends any[]>(
...apis: readonly [...TestApiProviderPropsApiPairs<TApiPairs>]
): TestApiRegistry;
get<T>(api: ApiRef<T>): T | undefined;
@@ -63,7 +63,7 @@ export class TestApiRegistry implements ApiHolder {
* @public
* @param apis - A list of pairs mapping an ApiRef to its respective implementation.
*/
static from<const TApiPairs extends any[]>(
static from<TApiPairs extends any[]>(
...apis: readonly [...TestApiProviderPropsApiPairs<TApiPairs>]
) {
return new TestApiRegistry(
@@ -124,7 +124,7 @@ export class TestApiRegistry implements ApiHolder {
*
* @public
*/
export const TestApiProvider = <const T extends any[]>(
export const TestApiProvider = <T extends any[]>(
props: TestApiProviderProps<T>,
) => {
return (