Skip to content

Don't emit named-arg values in bindInvokable, so generic helpers can't collapse curried types - #1249

Merged
NullVoxPopuli merged 3 commits into
typed-ember:mainfrom
BoussonKarel:fix-bind-invokable-generic-helper-arg
Sep 23, 2026
Merged

NullVoxPopuli merged 3 commits into
typed-ember:mainfrom
BoussonKarel:fix-bind-invokable-generic-helper-arg

Conversation

@BoussonKarel

Copy link
Copy Markdown
Contributor

Problem

A generic helper that returns a function, used as a named arg of {{component}}/{{helper}}/{{modifier}}, breaks the curried value's type. ember-set-helper's (set this "el") is the common case:

declare function setter<T extends object, K extends keyof T & string>(
  target: T,
  path: K,
): (value?: unknown) => T[K];

export class YieldCase extends Component<{
  Blocks: { default: [WithBoundArgs<typeof myModifier, 'onCreate'>] };
}> {
  el: HTMLElement | null = null;
  <template>{{yield (modifier myModifier onCreate=(setter this "el"))}}</template>
}
error TS2345: Argument of type '(element: HTMLElement, named: NamedArgs<{ onCreate: … }>) => ModifierReturn'
is not assignable to parameter of type '(element: HTMLElement, named?: PrebindArgs<{ onCreate: … }, "onCreate"> | undefined) => ModifierReturn'.
  • The same bind through {{#let}} doesn't error. That's only because its type has collapsed to Invokable<(...args: unknown[]) => unknown>, which accepts anything.
  • onCreate=this.onCreate (not generic) works.
  • This worked on @glint/ember-tsc 1.0.7 / @glint/template 1.7.2. It fails on 1.11.x / template 1.9.0.

Root cause

Since #1078 (fix for #1068, released in @glint/ember-tsc 1.2.3 / @glint/template 1.7.7), a curried keyword with named args emits a comma pair:

(resolve(modifier)((() => resolveForBind(myModifier))(), { onCreate: setter(this, "el") }),
 bindInvokable(resolveForBind(myModifier), { onCreate: setter(this, "el") }))

During its first inference pass, TypeScript skips any argument that is a call to a generic function returning a function (SkipGenericFunctions). setter(...) is such a call, and so is resolveForBind(...). With both skipped, bindInvokable infers none of its type parameters, and the result collapses to Invokable<(...args: unknown[]) => unknown>. When the value is yielded against WithBoundArgs, Args gets inferred from the expected type instead, and the modifier fails against it.

This is the mechanism behind #1147. The fix there only covered fn, by swapping it for the non-generic bindPositional inside bindInvokable. Any other helper with this shape still broke it.

It isn't caused by ember-set-helper's loose (value?: unknown) => T[K] return type. Before this change, all of these fail the same way:

hash value fails before
ember-set-helper's real signature yes
accurate overloads ((value: T[K]) => void / () => void) yes
strict (value: T[K]) => void yes
unconstrained <T>(x: T) => (e: HTMLElement) => void yes
generic helper returning a non-function (string) no
non-generic helper returning a function no

Fix

bindInvokable only reads the keys of its named args (keyof GivenNamed). The keyword call in the other half already validates the values, with the invokable's arg types as context. So the bindInvokable half now emits a placeholder for each value:

bindInvokable(resolveForBind(myModifier), { onCreate: boundArg, ...NamedArgsMarker })

As a result, fn's bindPositional special case can't be reached anymore, so it's removed. fn now always emits a plain call, which keeps the #1247 contextual typing.

Tests

🤖 Generated with Claude Code

BoussonKarel and others added 3 commits September 23, 2026 17:00
A curried keyword with named args emits a comma pair (typed-ember#1068): the keyword
call validates the args, and `bindInvokable(...)` produces the curried
value. When a named arg's value was a call to a generic function that
returns a function, like ember-set-helper's `(set this "el")`, TypeScript
skipped it during `bindInvokable`'s first inference pass
(`SkipGenericFunctions`). Together with the likewise-skipped
`resolveForBind(...)`, that lost all of `bindInvokable`'s type parameters
and collapsed the result to `Invokable<(...args: unknown[]) => unknown>`.
Yielded against `WithBoundArgs`, `Args` was then inferred from the expected
type and valid code was rejected.

`bindInvokable` only reads the named args' keys, so the transform now emits
`boundArg` for every value there. This generalizes the typed-ember#1147 fix, which
covered only `fn`, so the `bindPositional` special case is removed and
`fn` always emits a plain call (typed-ember#1247).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@NullVoxPopuli
NullVoxPopuli merged commit ff64382 into typed-ember:main Sep 23, 2026
13 of 14 checks passed
@NullVoxPopuli NullVoxPopuli added the bug Something isn't working label Sep 23, 2026
@github-actions github-actions Bot mentioned this pull request Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants