Skip to content

feat(core): add type-safe ActionOptionsConfig overload to execute()#16

Merged
minseong0324 merged 3 commits intomainfrom
fix/execute-type-safe
Feb 25, 2026
Merged

feat(core): add type-safe ActionOptionsConfig overload to execute()#16
minseong0324 merged 3 commits intomainfrom
fix/execute-type-safe

Conversation

@minseong0324
Copy link
Owner

@minseong0324 minseong0324 commented Feb 25, 2026

Summary

client.execute() previously accepted only a string actionKey, causing the
returned result to always be typed as unknown. This PR adds a second overload
that accepts an ActionOptionsConfig directly, enabling full TInput/TResult
inference without any manual cast at the call site.

Changes

@connectivity-js/core

types.ts

  • ActionRunResult is now generic: ActionRunResult<TResult = unknown>
    • Fully backward-compatible (default keeps unknown)

connectivity-client.ts

  • Added execute(config: ActionOptionsConfig<TInput, TResult>, input: TInput) overload
    • Calls config.request(input) directly — no Map lookup, TResult fully inferred
    • Auto-registers the action if not already registered; preserves existing
      registration (and its flush callbacks) if it is
  • Added private helpers #onImmediateSuccess and #registerFromConfig to reduce
    duplication

action-observer.ts

  • ActionObserver.execute() continues to use the string overload intentionally
    • Keeps behavior consistent with the queue-flush path (both always go through the Map)
    • Ensures registerAction() overrides are respected in the immediate-execution path
    • The single as TResult cast is safe: setOptions()#register() keeps the
      Map in sync with the declared TResult on every render

Type safety

Call site result type
client.execute('save', input) unknown (unchanged)
client.execute(saveAction, input) inferred from saveAction.request return type ✅

Behavior

No behavioral changes to existing string-key calls.
The config overload is additive; registerAction() overrides are still respected
through ActionObserver.

Checklist

  • I followed the steps in the Contributing guide.
  • I ran pnpm run test locally and all tests pass.

Release impact

  • This change touches published packages, so I added a changeset.
  • This change is docs/CI/dev-only and does not require a release.

@vercel
Copy link

vercel bot commented Feb 25, 2026

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

Project Deployment Actions Updated (UTC)
connectivity-js-docs Ready Ready Preview, Comment Feb 25, 2026 10:01am

@minseong0324 minseong0324 self-assigned this Feb 25, 2026
@minseong0324 minseong0324 merged commit d051566 into main Feb 25, 2026
4 checks passed
@github-actions github-actions bot mentioned this pull request Feb 25, 2026
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