frontend-plugin-api: implement .T on route refs as declared props

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-10-12 14:36:54 +02:00
parent d84f5efa60
commit 6b4ae484ad
4 changed files with 4 additions and 10 deletions
@@ -21,7 +21,7 @@ describe('RouteRef', () => {
it('should be created and have a mutable ID', () => {
const routeRef: RouteRef<undefined> = createRouteRef();
const internal = toInternalRouteRef(routeRef);
expect(() => internal.T).toThrow();
expect(internal.T).toBe(undefined);
expect(internal.getParams()).toEqual([]);
expect(internal.getDescription()).toMatch(/RouteRef\.test\.ts/);
@@ -51,7 +51,6 @@ describe('RouteRef', () => {
const internal = toInternalRouteRef(routeRef);
expect(internal.getParams()).toEqual(['x', 'y']);
expect(internal.getDescription()).toMatch(/RouteRef\.test\.ts/);
expect(() => internal.T).toThrow();
});
it('should properly infer and validate parameter types and assignments', () => {
@@ -63,6 +63,7 @@ export function isRouteRef(opaque: { $$type: string }): opaque is RouteRef {
export class RouteRefImpl implements InternalRouteRef {
readonly $$type = '@backstage/RouteRef';
readonly version = 'v1';
declare readonly T: never;
#id?: string;
#params: string[];
@@ -73,10 +74,6 @@ export class RouteRefImpl implements InternalRouteRef {
this.#creationSite = creationSite;
}
get T(): never {
throw new Error(`tried to read RouteRef.T of ${this}`);
}
getParams(): string[] {
return this.#params;
}
@@ -34,6 +34,7 @@ describe('SubRouteRef', () => {
});
const internal = toInternalSubRouteRef(routeRef);
expect(internal.path).toBe('/foo');
expect(internal.T).toBe(undefined);
expect(internal.getParent()).toBe(internalParent);
expect(internal.getParams()).toEqual([]);
expect(String(internal)).toMatch(
@@ -73,6 +73,7 @@ export class SubRouteRefImpl<TParams extends AnyRouteParams>
{
readonly $$type = '@backstage/SubRouteRef';
readonly version = 'v1';
declare readonly T: never;
#params: string[];
#parent: RouteRef;
@@ -82,10 +83,6 @@ export class SubRouteRefImpl<TParams extends AnyRouteParams>
this.#parent = parent;
}
get T(): never {
throw new Error(`tried to read RouteRef.T of ${this}`);
}
getParams(): string[] {
return this.#params;
}