api-ref: preserve const ids in builder types

Use a const type parameter for createApiRef().with(...) so literal API ref ids stay narrow instead of widening to string.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
This commit is contained in:
Patrik Oldsberg
2026-03-17 10:46:42 +01:00
parent 4690f20880
commit 90c3a9d1c0
2 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -444,7 +444,7 @@ export function createApiRef<T>(config: ApiRefConfig): ApiRef<T> & {
// @public
export function createApiRef<T>(): {
with<TId extends string>(
with<const TId extends string>(
config: ApiRefConfig & {
id: TId;
pluginId?: string;
@@ -119,7 +119,7 @@ export function createApiRef<T>(
* @public
*/
export function createApiRef<T>(): {
with<TId extends string>(
with<const TId extends string>(
config: ApiRefConfig & { id: TId; pluginId?: string },
): ApiRef<T, TId> & {
readonly $$type: '@backstage/ApiRef';
@@ -128,7 +128,7 @@ export function createApiRef<T>(): {
export function createApiRef<T>(config?: ApiRefConfig):
| (ApiRef<T> & { readonly $$type: '@backstage/ApiRef' })
| {
with<TId extends string>(
with<const TId extends string>(
config: ApiRefConfig & { id: TId; pluginId?: string },
): ApiRef<T, TId> & {
readonly $$type: '@backstage/ApiRef';
@@ -139,7 +139,7 @@ export function createApiRef<T>(config?: ApiRefConfig):
return makeApiRef<T, string>(config);
}
return {
with<TId extends string>(
with<const TId extends string>(
withConfig: ApiRefConfig & { id: TId; pluginId?: string },
): ApiRef<T, TId> & { readonly $$type: '@backstage/ApiRef' } {
validateId(withConfig.id);