Skip to content

TS SDK: add withArgNames for explicit argument renames - #73191

Merged
jason810496 merged 1 commit into
apache:mainfrom
jason810496:feature/ts-sdk/with-arg-names
Sep 19, 2026
Merged

jason810496 merged 1 commit into
apache:mainfrom
jason810496:feature/ts-sdk/with-arg-names

Conversation

@jason810496

@jason810496 jason810496 commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

TS SDK: add withArgNames for explicit argument renames

Why

Folding absorbs spelling differences, but not a name the Python side never used:
a handler that wants to call run_label simply label, or one whose argument is a TypeScript reserved word like enum.

How

  • withArgNames(map, handler), mapping first. An entry beats folding, and everything the map does not mention still folds,
    which is what keeps this rare in a real Dag.
  • The map's keys are checked against the handler's own parameter type, so { labl: "run_label" } is a compile error naming the right key.
    Its type parameter is NoInfer, so the parameter type comes from the handler alone;
    inferring it from the map too would make every key correct by construction and the check vacuous.
    The values are Python names, which tsc cannot see and does not check.
  • A mapped name the call did not pass misses rather than falling back to folding,
    so a stated binding that is wrong is visible instead of silently replaced by a guess.
    The unbound-argument warning now also names the wire name that was asked for.
  • The renames travel with the handler on a global symbol and are read back at the dispatch site.
    The return value is a wrapper rather than the author's own function with a property attached,
    because one handler can be registered for two tasks that rename differently.
  • The shipped example gains a report task whose handler renames run_label to label and throws unless it bound correctly,
    so a rename that did not take effect fails the end-to-end run rather than returning a null.

Was generative AI tooling used to co-author this PR?

@jason810496
jason810496 force-pushed the feature/ts-sdk/with-arg-names branch 15 times, most recently from 7ba4226 to 7427c1d Compare September 18, 2026 03:16
@jason810496 jason810496 self-assigned this Sep 18, 2026
@jason810496
jason810496 force-pushed the feature/ts-sdk/with-arg-names branch 4 times, most recently from 91646ed to 932668c Compare September 18, 2026 10:07
@jason810496
jason810496 marked this pull request as ready for review September 18, 2026 10:17
@jason810496
jason810496 marked this pull request as draft September 18, 2026 15:38
Folding absorbs spelling differences, so a Python `region_code` reaches a
handler's `regionCode` with nothing declared. What it cannot reach is a name
the Python side never used: a handler that wants to call `run_label` simply
`label`, or one whose argument is a TypeScript reserved word like `enum`. Until
now the only options were to rename the Python parameter, or to read the
argument under Python's name and shadow it locally.

`withArgNames` states that binding. The mapping comes first and the handler
second, so the map reads as a qualifier on the handler rather than an extra
parameter, and an entry takes precedence over folding. Everything the map does
not mention still folds, which is the property that keeps this rare.

The map's keys are checked against the handler's own parameter type, so
`{ labl: "run_label" }` is a compile error naming the right key, since a
mapping for a name the handler does not have would silently do nothing. That
check needs the parameter type to come from the handler alone, so the map's
type parameter is `NoInfer`: inferring it from the map too would make every key
correct by construction and the check vacuous.

A mapped name the call did not pass misses rather than falling back to folding.
An author who stated a binding that is wrong should see the miss, not a value
the SDK guessed at, so the unbound-argument warning now also names the wire
name that was asked for.

The renames travel with the handler on a global symbol and are read back at the
dispatch site, which is also why the returned value is a wrapper rather than
the author's own function with a property attached: one handler can be
registered for two tasks that rename differently, and mutating it would let the
second registration silently change the first.
@jason810496
jason810496 force-pushed the feature/ts-sdk/with-arg-names branch from 1e89ceb to 3411603 Compare September 18, 2026 15:39
@jason810496
jason810496 marked this pull request as ready for review September 19, 2026 03:26
@jason810496
jason810496 merged commit bd65f79 into apache:main Sep 19, 2026
92 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants