diff --git a/.changeset/tighten-internal-any-usage.md b/.changeset/tighten-internal-any-usage.md new file mode 100644 index 0000000000..acbeecdd3e --- /dev/null +++ b/.changeset/tighten-internal-any-usage.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-plugin-api': patch +--- + +Added stricter type checks in `isDatabaseConflictError`. diff --git a/packages/backend-plugin-api/src/services/system/types.ts b/packages/backend-plugin-api/src/services/system/types.ts index 7e4b78b5a1..c6425cca42 100644 --- a/packages/backend-plugin-api/src/services/system/types.ts +++ b/packages/backend-plugin-api/src/services/system/types.ts @@ -136,8 +136,8 @@ export function createServiceRef< TService, TInstances extends 'singleton' | 'multiton', >( - options: ServiceRefOptions, -): ServiceRef { + options: ServiceRefOptions, +): ServiceRef { const { id, scope = 'plugin', multiton = false, defaultFactory } = options; return { id, diff --git a/packages/backend-plugin-api/src/services/utilities/database.ts b/packages/backend-plugin-api/src/services/utilities/database.ts index f5abcd7fba..6a550c0d78 100644 --- a/packages/backend-plugin-api/src/services/utilities/database.ts +++ b/packages/backend-plugin-api/src/services/utilities/database.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +import { isError } from '@backstage/errors'; + /** * Tries to deduce whether a thrown error is a database conflict. * @@ -23,7 +25,7 @@ * known database engine */ export function isDatabaseConflictError(e: unknown) { - const message = (e as any)?.message; + const message = isError(e) ? e.message : undefined; return ( typeof message === 'string' && diff --git a/packages/backend-plugin-api/src/wiring/types.ts b/packages/backend-plugin-api/src/wiring/types.ts index 28b70b547f..9397cf597b 100644 --- a/packages/backend-plugin-api/src/wiring/types.ts +++ b/packages/backend-plugin-api/src/wiring/types.ts @@ -56,7 +56,11 @@ type DepsToInstances< [key in string]: ServiceRef | ExtensionPoint; }, > = { - [key in keyof TDeps]: TDeps[key] extends ServiceRef + [key in keyof TDeps]: TDeps[key] extends ServiceRef< + unknown, + 'root' | 'plugin', + 'multiton' + > ? Array : TDeps[key]['T']; };