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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user