Skip to content

fix(types): correct Asset type definition from string literal to string union#3323

Merged
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
yogeshwaran-c:fix/asset-type-definition
Apr 8, 2026
Merged

fix(types): correct Asset type definition from string literal to string union#3323
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
yogeshwaran-c:fix/asset-type-definition

Conversation

@yogeshwaran-c

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix (type definition correction)

What is the current behavior?

The Asset type in lib/configuration/configuration.ts is defined as:

export type Asset = 'string' | AssetEntry;

This is a string literal type — it only matches the exact word "string", not any arbitrary string. This has been incorrect since the type was first introduced in v6.10.0 (commit 698c460).

Additionally, CompilerOptions.assets is typed as string[], which doesn't account for AssetEntry objects that are also valid asset values.

What is the new behavior?

  1. Asset type is corrected from 'string' | AssetEntry to string | AssetEntry — a proper union of any string with AssetEntry objects.

  2. CompilerOptions.assets is updated from string[] to Asset[] — correctly reflecting that assets can be either glob strings (e.g., "**/*.graphql") or AssetEntry objects (e.g., { include: "**/*.hbs", outDir: "dist" }).

This matches the runtime behavior in AssetsManager.copyAssets() which checks typeof item === 'string' to differentiate between the two forms.

Additional context

  • Zero runtime impact (types are erased at compile time)
  • All existing tests pass
  • TypeScript compilation (tsc --noEmit) passes with no errors
  • The typo has existed since October 2019 when the Asset type was first introduced

…ng union

The `Asset` type was defined as `'string' | AssetEntry` (a literal string
type matching only the word "string") instead of `string | AssetEntry`
(any string). This typo has existed since the type was introduced in v6.10.0.

Also updates `CompilerOptions.assets` from `string[]` to `Asset[]` so
that the type correctly reflects that assets can be either glob strings
or `AssetEntry` objects, matching the actual runtime behavior in
`AssetsManager.copyAssets()`.
@kamilmysliwiec kamilmysliwiec merged commit 4dad3d3 into nestjs:master Apr 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants