Skip to content

fix(definition): infer lazy args from inline definitions#585

Merged
kazupon merged 1 commit into
mainfrom
codex/fix-lazy-definition-inference
Jun 15, 2026
Merged

fix(definition): infer lazy args from inline definitions#585
kazupon merged 1 commit into
mainfrom
codex/fix-lazy-definition-inference

Conversation

@kazupon

@kazupon kazupon commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes lazy command inference so inline definitions with args feed their schema into the loader context.

This addresses Issue #582: lazy(() => ..., { args }) no longer widens ctx.values.foo to the default string/number/boolean union.

The new overload derives args from the provided definition while preserving explicit generic usage and args-less fallback behavior.

Type tests cover the StackBlitz reproduction plus required, optional, and defaulted arg values.

Summary by CodeRabbit

  • Improvements

    • Enhanced type inference for lazy-loaded commands, enabling better type inference from inline definitions without explicit generic type parameters
    • Improved type safety validation for command extension configurations with stricter property checking
    • Made definition parameters optional for lazy loaders while maintaining command metadata type preservation
  • Tests

    • Expanded test coverage for edge cases in type inference and definition handling

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 63e2d8b9-2b99-41c4-a5f7-dd1ca1058c77

📥 Commits

Reviewing files that changed from the base of the PR and between 789136d and fee2730.

📒 Files selected for processing (2)
  • packages/gunshi/src/definition.test-d.ts
  • packages/gunshi/src/definition.ts

📝 Walkthrough

Walkthrough

The lazy function overloads in definition.ts are refactored to drop the standalone A extends Args generic, make definition optional, and constrain D directly to Partial<Command<G>>. GunshiParams is removed from imports in favor of GunshiParamsConstraint. JSDoc references are updated accordingly, and new type-level tests validate the corrected inference behavior.

Changes

lazy overload generics and type tests

Layer / File(s) Summary
lazy overload signature and generics refactor
packages/gunshi/src/definition.ts
Removes GunshiParams from type-only imports. Rewrites the main lazy overload to use D extends Partial<Command<G>> with definition?: D, drops the standalone A extends Args generic, and aligns D['args']-based loader/return types in the inline-definition overload. Updates @typeParam G JSDoc in defineWithTypes, LazyWithTypesReturn, and lazyWithTypes from GunshiParams to GunshiParamsConstraint.
Type-level tests for lazy inference and extension assertions
packages/gunshi/src/definition.test-d.ts
Changes "missing extension" assertions in define and defineWithTypes tests to toHaveProperty('missing') with @ts-expect-error. Adds new lazy tests: loader context inference from an inline definition without an explicit extensions generic (Issue #582), arg value type inference (values.input, values.count, values.verbose), and metadata preservation (commandName) when args is omitted.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • kazupon/gunshi#566: Directly modifies the same lazy/lazyWithTypes overload generics and return-type inference in definition.ts.
  • kazupon/gunshi#177: Introduced the GunshiParams-based Command/CommandContext generics and extensions typing that this PR's overload changes and test assertions are built on top of.

Suggested labels

improvement

🐇 A hop, a skip, through generic land,
D extends Partial<Command> — just as planned!
No more standalone A to roam,
The loader types feel right at home.
Extensions checked with toHaveProperty flair,
Type safety blooms beyond compare! 🌸

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(definition): infer lazy args from inline definitions' directly and clearly describes the main change - fixing lazy command argument inference from inline definitions, which is the core objective of the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-lazy-definition-inference

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.

@pkg-pr-new

pkg-pr-new Bot commented Jun 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

@gunshi/bone

npm i https://pkg.pr.new/@gunshi/bone@585

@gunshi/combinators

npm i https://pkg.pr.new/@gunshi/combinators@585

@gunshi/definition

npm i https://pkg.pr.new/@gunshi/definition@585

@gunshi/docs

npm i https://pkg.pr.new/@gunshi/docs@585

gunshi

npm i https://pkg.pr.new/gunshi@585

@gunshi/plugin

npm i https://pkg.pr.new/@gunshi/plugin@585

@gunshi/plugin-completion

npm i https://pkg.pr.new/@gunshi/plugin-completion@585

@gunshi/plugin-dryrun

npm i https://pkg.pr.new/@gunshi/plugin-dryrun@585

@gunshi/plugin-global

npm i https://pkg.pr.new/@gunshi/plugin-global@585

@gunshi/plugin-i18n

npm i https://pkg.pr.new/@gunshi/plugin-i18n@585

@gunshi/plugin-renderer

npm i https://pkg.pr.new/@gunshi/plugin-renderer@585

@gunshi/resources

npm i https://pkg.pr.new/@gunshi/resources@585

@gunshi/shared

npm i https://pkg.pr.new/@gunshi/shared@585

commit: fee2730

@kazupon kazupon marked this pull request as ready for review June 15, 2026 01:33
@kazupon kazupon added the bug Includes new features label Jun 15, 2026
@kazupon

kazupon commented Jun 15, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kazupon kazupon merged commit 6b32b9c into main Jun 15, 2026
10 checks passed
@kazupon kazupon deleted the codex/fix-lazy-definition-inference branch June 15, 2026 01:39
@kazupon kazupon mentioned this pull request Jun 16, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Includes new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant