Skip to content

refactor(types): avoid DeepPartial#3888

Merged
pi0 merged 1 commit into
mainfrom
refactor/types-deep
Dec 18, 2025
Merged

refactor(types): avoid DeepPartial#3888
pi0 merged 1 commit into
mainfrom
refactor/types-deep

Conversation

@pi0
Copy link
Copy Markdown
Member

@pi0 pi0 commented Dec 18, 2025

Nitro input config was marked as DeepPartial while it makes impl little eaiser makes type complexity higher (now failing for rollup config in #3887) but also it introduces implicit types.

@vercel
Copy link
Copy Markdown

vercel Bot commented Dec 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
nitro.build Ready Ready Preview, Comment Dec 18, 2025 8:53pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 18, 2025

📝 Walkthrough

Walkthrough

Multiple defensive programming patterns added across the codebase including optional chaining, nullish coalescing, and default fallbacks. Type definitions significantly relaxed to make numerous NitroOptions fields optional using Partial patterns instead of DeepPartial. Configuration initialization ensures objects exist before modification.

Changes

Cohort / File(s) Summary
Type System Refactoring
src/types/_utils.ts, src/types/config.ts
Removed exported DeepPartial utility type. Substantially refactored NitroOptions to use Partial patterns; made runtimeHooks, websocket, imports, devServer, logging, prerender sub-fields (autoSubfolderIndex, concurrency, interval, crawlLinks, failOnError, ignore, ignoreUnprefixedPublicAssets, routes, retry, retryDelay), tsconfigPath, and commands optional. NitroConfig now extends Partial<Omit<NitroOptions, ..., "output">> instead of DeepPartial and adds optional output field. NitroRuntimeConfig.nitro made optional. Removed DeepPartial import.
Configuration Type Definition
src/presets/vercel/types.ts
Made VercelOptions.config field optional by changing type from config: VercelBuildConfigV3 to config?: VercelBuildConfigV3.
Build Configuration
src/build/types.ts
Added default fallback for tsconfig path resolution: nitro.options.typescript.tsconfigPath || "tsconfig.json" when computing TSConfigPath.
Runtime Safe Access Patterns
src/runtime/internal/routes/scalar.ts, src/runtime/internal/routes/swagger.ts
Replaced direct property access on runtimeConfig.nitro with optional chaining (runtimeConfig.nitro?.openAPI?.meta?.title, etc.) to safely guard against missing intermediate objects; preserves existing fallback defaults.
Defensive Guard Initialization
src/config/resolvers/database.ts, src/config/resolvers/runtime-config.ts, src/dev/server.ts
Added initialization guards: options.imports.presets ??= [] before pushing, runtimeConfig.nitro ??= {} before assignment, and locally scoped devWatch constant with null/undefined check before watcher initialization.
Prerender Robustness
src/prerender/prerender.ts
Added conditional guard for ignore-pattern iteration, defaulted crawlLinks to false if undefined using nullish coalescing, and defaulted concurrency to 1 if falsy during parallel generation.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • src/types/config.ts: Extensive public API surface changes making numerous fields optional; requires validation that code consuming these fields handles undefined values appropriately across the codebase
  • src/types/_utils.ts: DeepPartial removal may have cascading impacts; verify all usages have been refactored in config.ts and that no other files depend on this utility
  • Optional chaining in runtime routes: Verify fallback defaults are correctly applied and that all undefined intermediate objects result in expected behavior
  • Nullish coalescing patterns: Confirm initialization order and that subsequent property assignments don't depend on earlier structure assumptions across database.ts, runtime-config.ts, and dev/server.ts

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title follows conventional commits format with 'refactor(types):' prefix and clearly describes the main change of removing DeepPartial usage from type definitions.
Description check ✅ Passed The description explains the problem (DeepPartial increasing type complexity) and the solution (refactoring types to avoid it), directly relating to the changeset modifications.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/types-deep

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 077b79b and 1d85171.

📒 Files selected for processing (10)
  • src/build/types.ts (1 hunks)
  • src/config/resolvers/database.ts (1 hunks)
  • src/config/resolvers/runtime-config.ts (1 hunks)
  • src/dev/server.ts (1 hunks)
  • src/prerender/prerender.ts (3 hunks)
  • src/presets/vercel/types.ts (1 hunks)
  • src/runtime/internal/routes/scalar.ts (1 hunks)
  • src/runtime/internal/routes/swagger.ts (1 hunks)
  • src/types/_utils.ts (0 hunks)
  • src/types/config.ts (9 hunks)
💤 Files with no reviewable changes (1)
  • src/types/_utils.ts
🧰 Additional context used
🧬 Code graph analysis (2)
src/prerender/prerender.ts (1)
src/prerender/utils.ts (1)
  • matchesIgnorePattern (112-127)
src/types/config.ts (2)
src/types/module.ts (1)
  • NitroModuleInput (3-7)
src/types/hooks.ts (1)
  • NitroHooks (9-33)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: tests-rollup (ubuntu-latest)
  • GitHub Check: tests-rolldown (windows-latest)
  • GitHub Check: tests-rollup (windows-latest)
🔇 Additional comments (15)
src/config/resolvers/database.ts (1)

5-5: LGTM! Safe initialization aligns with type refactoring.

The nullish coalescing assignment ensures presets is an array before the push operation on line 6. This defensive pattern is necessary now that types avoid DeepPartial, making previously deep-optional fields explicitly optional.

src/config/resolvers/runtime-config.ts (1)

27-28: LGTM - Defensive initialization is correct.

The nullish coalescing assignment ensures runtimeConfig.nitro exists before setting routeRules, which is necessary since NitroRuntimeConfig.nitro is now optional. This correctly handles edge cases where defu might not initialize nitro (e.g., if explicitly set to undefined).

src/build/types.ts (1)

191-194: LGTM - Sensible default for optional tsconfigPath.

The fallback to "tsconfig.json" is appropriate given that tsconfigPath is now optional in the type definitions. This ensures resolve() receives a valid path string.

src/dev/server.ts (1)

94-99: LGTM - Proper guard for optional watch configuration.

Extracting devServer.watch to a local variable and guarding against undefined/empty arrays prevents creating an unnecessary file watcher when watch paths aren't configured. This aligns with watch becoming optional in NitroOptions.devServer.

src/prerender/prerender.ts (3)

150-156: LGTM - Proper guard for optional ignore patterns.

The conditional check before iterating prevents errors when prerender.ignore is undefined, aligning with the type change making ignore optional.


327-328: LGTM - Correct default for optional crawlLinks.

The nullish coalescing to false ensures extractLinks receives a boolean when crawlLinks is undefined, matching the expected parameter type.


349-351: LGTM - Sensible default concurrency.

Defaulting to 1 when concurrency is undefined ensures sequential processing as a safe fallback.

src/runtime/internal/routes/swagger.ts (1)

9-12: LGTM - Proper optional chaining for runtime config access.

The optional chaining correctly handles the case where runtimeConfig.nitro is undefined, with sensible fallback values preserved.

src/runtime/internal/routes/scalar.ts (1)

8-15: LGTM - Consistent optional chaining pattern.

The changes mirror the pattern in swagger.ts, correctly handling the optional runtimeConfig.nitro with appropriate fallback values.

src/types/config.ts (5)

97-103: LGTM - Optional feature flags.

Making runtimeHooks and websocket optional in features is appropriate as these have conditional defaults (e.g., runtimeHooks depends on plugin presence).


164-167: LGTM - Relaxed imports and tasks typing.

Using Partial<UnimportPluginOptions> instead of the full type, and making task handler optional, provides flexibility for incremental configuration.


205-229: LGTM - Optional prerender configuration.

Making prerender sub-fields optional aligns with the defensive patterns added in src/prerender/prerender.ts (guards for ignore, defaults for concurrency and crawlLinks).


289-318: Clean refactor from DeepPartial to explicit Partial with omissions.

The approach of using Partial<Omit<NitroOptions, ...>> with explicit handling of output as Partial<NitroOptions["output"]> is cleaner than DeepPartial and provides better type inference. This directly addresses the rollup config failure mentioned in issue #3887.


391-399: LGTM - Optional nitro in NitroRuntimeConfig.

Making nitro optional aligns with the defensive patterns added in runtime-config.ts (nullish coalescing assignment) and the optional chaining in swagger.ts/scalar.ts.

src/presets/vercel/types.ts (1)

112-113: Optional config field is properly handled by consumers.

Verification confirms that all usages of VercelOptions.config employ optional chaining (?.) to safely handle the undefined case. Specifically, line 74 uses nitro.options.vercel?.config?.bypassToken and line 134 uses defu(nitro.options.vercel?.config, ...), both of which correctly handle the optional field without risk of runtime errors.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pi0 pi0 merged commit 3992c73 into main Dec 18, 2025
8 of 9 checks passed
@pi0 pi0 deleted the refactor/types-deep branch December 18, 2025 20:56
@coderabbitai coderabbitai Bot mentioned this pull request Apr 13, 2026
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant