From 6b4ae484adba5d08d8f6fb2cab20c08501442668 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 12 Oct 2023 14:36:54 +0200 Subject: [PATCH] frontend-plugin-api: implement .T on route refs as declared props Signed-off-by: Patrik Oldsberg --- packages/frontend-plugin-api/src/routing/RouteRef.test.ts | 3 +-- packages/frontend-plugin-api/src/routing/RouteRef.ts | 5 +---- packages/frontend-plugin-api/src/routing/SubRouteRef.test.ts | 1 + packages/frontend-plugin-api/src/routing/SubRouteRef.ts | 5 +---- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/frontend-plugin-api/src/routing/RouteRef.test.ts b/packages/frontend-plugin-api/src/routing/RouteRef.test.ts index cb1c85ccea..c8d7c22e35 100644 --- a/packages/frontend-plugin-api/src/routing/RouteRef.test.ts +++ b/packages/frontend-plugin-api/src/routing/RouteRef.test.ts @@ -21,7 +21,7 @@ describe('RouteRef', () => { it('should be created and have a mutable ID', () => { const routeRef: RouteRef = 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', () => { diff --git a/packages/frontend-plugin-api/src/routing/RouteRef.ts b/packages/frontend-plugin-api/src/routing/RouteRef.ts index f8ca088d0f..1085644993 100644 --- a/packages/frontend-plugin-api/src/routing/RouteRef.ts +++ b/packages/frontend-plugin-api/src/routing/RouteRef.ts @@ -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; } diff --git a/packages/frontend-plugin-api/src/routing/SubRouteRef.test.ts b/packages/frontend-plugin-api/src/routing/SubRouteRef.test.ts index 7e8efe7842..5b1ef6d836 100644 --- a/packages/frontend-plugin-api/src/routing/SubRouteRef.test.ts +++ b/packages/frontend-plugin-api/src/routing/SubRouteRef.test.ts @@ -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( diff --git a/packages/frontend-plugin-api/src/routing/SubRouteRef.ts b/packages/frontend-plugin-api/src/routing/SubRouteRef.ts index 3fb3778d6f..b71ceb6a95 100644 --- a/packages/frontend-plugin-api/src/routing/SubRouteRef.ts +++ b/packages/frontend-plugin-api/src/routing/SubRouteRef.ts @@ -73,6 +73,7 @@ export class SubRouteRefImpl { readonly $$type = '@backstage/SubRouteRef'; readonly version = 'v1'; + declare readonly T: never; #params: string[]; #parent: RouteRef; @@ -82,10 +83,6 @@ export class SubRouteRefImpl this.#parent = parent; } - get T(): never { - throw new Error(`tried to read RouteRef.T of ${this}`); - } - getParams(): string[] { return this.#params; }