Dynatrace / Dynatrace/backstage-plugin
`config.d.ts` union type precedence bug causes config validation failure for `dynatrace.environments`
- Dominant language
- TypeScript
- Stars
- 37
- Forks
- 19
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 2
Description
# Summary
The TypeScript union type definition for `environments` in `plugins/dql-backend/config.d.ts` has incorrect operator precedence, causing Backstage's config schema compiler to generate an `object` type instead of an `array` type. This makes the app fail to start with a config validation error when using the documented array format for `dynatrace.environments`.
## Expected Behavior
Backstage should start successfully when `dynatrace.environments` is configured as an array, as shown in the plugin's own README documentation:
```yaml
dynatrace:
environments:
- name: xxxxxxxx
url: https://xxxxxxxx.apps.dynatrace.com
tokenUrl: https://sso.dynatrace.com/sso/oauth2/token
accountUrn:
clientId:
clientSecret:
```
## Current Behavior
Backstage fails to start with the following error:
```
Plugin 'app' threw an error during startup. Invalid app bundle schema.
Caused by: Config validation failed, Config must be object { type=object } at /dynatrace/environments
```
## Steps to Reproduce
1. Install `@dynatrace/backstage-plugin-dql-backend` v2.6.0
2. Configure `dynatrace.environments` as an array in `app-config.yaml` (following the README)
3. Build the app with `yarn --cwd packages/app build`
4. Start the backend
## Possible Solution
The issue is in `plugins/dql-backend/config.d.ts` 19. The current type:
```typescript
environments:
{ /* OAuthConfig */ } | { /* TokenConfig */ }[],
```
Due to TypeScript operator precedence, this is parsed as `OAuthConfig | (TokenConfig[])` — a union of a single object or an array. Backstage's config schema compiler picks the first branch (object) and generates `{ type: "object" }` for the JSON schema.
The fix is to wrap the union in parentheses so the array applies to both types:
```typescript
environments:
({ /* OAuthConfig */ } | { /* TokenConfig */ })[],
```
This makes it unambiguously `(OAuthConfig | TokenConfig)[]` — an array of either type, which matches the documented config format.
## Context
This prevents deploying Backstage with the Dynatrace DQL plugin in any environment where the app bundle is built.
The error occurs in `@backstage/plugin-app-backend` at `readFrontendConfig.cjs.js:26` during config schema validation against the compiled app bundle.
## Your Environment
- `@dynatrace/backstage-plugin-dql-backend` version: 2.6.0
- `@dynatrace/backstage-plugin-dql` version: 2.6.0
Contributor guide
Assessment
This issue has not been assessed yet.