Fix typing on withApis() when multiple APIs provided
Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-techdocs-addons-test-utils': patch
|
||||
---
|
||||
|
||||
Fixed a type bug preventing `buildAddonsInTechDocs().withApis()` from being called with multiple partial API implementations.
|
||||
@@ -29,7 +29,7 @@ export class TechDocsAddonTester {
|
||||
}
|
||||
>;
|
||||
// (undocumented)
|
||||
withApis<T>(apis: TechdocsAddonTesterApis<T>): this;
|
||||
withApis<T extends any[]>(apis: TechdocsAddonTesterApis<T>): this;
|
||||
// (undocumented)
|
||||
withDom(dom: ReactElement): this;
|
||||
// (undocumented)
|
||||
|
||||
@@ -65,14 +65,18 @@ type TechDocsAddonTesterTestApiPair<TApi> = TApi extends infer TImpl
|
||||
: never;
|
||||
|
||||
/** @ignore */
|
||||
type TechdocsAddonTesterApis<T> = TechDocsAddonTesterTestApiPair<T>[];
|
||||
type TechdocsAddonTesterApis<TApiPairs> = {
|
||||
[TIndex in keyof TApiPairs]: TechDocsAddonTesterTestApiPair<
|
||||
TApiPairs[TIndex]
|
||||
>;
|
||||
};
|
||||
|
||||
type TechDocsAddonTesterOptions = {
|
||||
dom: ReactElement;
|
||||
entity: Partial<TechDocsEntityMetadata>;
|
||||
metadata: Partial<TechDocsMetadata>;
|
||||
componentId: string;
|
||||
apis: TechdocsAddonTesterApis<any>;
|
||||
apis: TechdocsAddonTesterApis<any[]>;
|
||||
path: string;
|
||||
};
|
||||
|
||||
@@ -125,7 +129,7 @@ export class TechDocsAddonTester {
|
||||
this.addons = addons;
|
||||
}
|
||||
|
||||
withApis<T>(apis: TechdocsAddonTesterApis<T>) {
|
||||
withApis<T extends any[]>(apis: TechdocsAddonTesterApis<T>) {
|
||||
const refs = apis.map(([ref]) => ref);
|
||||
this.options.apis = this.options.apis
|
||||
.filter(([ref]) => !refs.includes(ref))
|
||||
@@ -154,7 +158,7 @@ export class TechDocsAddonTester {
|
||||
}
|
||||
|
||||
build() {
|
||||
const apis: TechdocsAddonTesterApis<any> = [
|
||||
const apis: TechdocsAddonTesterApis<any[]> = [
|
||||
[techdocsApiRef, techdocsApi],
|
||||
[techdocsStorageApiRef, techdocsStorageApi],
|
||||
[searchApiRef, searchApi],
|
||||
|
||||
Reference in New Issue
Block a user