Skip to content

fix(core): allow explicit read generic with signal input transforms#67997

Merged
alxhub merged 1 commit into
angular:mainfrom
cexbrayat:fix/input-transform-explicit-generic
May 1, 2026
Merged

fix(core): allow explicit read generic with signal input transforms#67997
alxhub merged 1 commit into
angular:mainfrom
cexbrayat:fix/input-transform-explicit-generic

Conversation

@cexbrayat

@cexbrayat cexbrayat commented Apr 2, 2026

Copy link
Copy Markdown
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Using explicit single generic arguments with transforms, e.g. input<boolean>(false, {transform: booleanAttribute}), failed overload resolution.

Before this fix, type-checking produced:

 [ERROR] TS2769: No overload matches this call.
  Overload 1 of 5, '(initialValue: boolean, opts?: InputOptionsWithoutTransform<boolean> | undefined): InputSignal<boolean>', gave the following error.
    Type '(value: unknown) => boolean' is not assignable to type 'undefined'.
  Overload 2 of 5, '(initialValue: undefined, opts: InputOptionsWithoutTransform<boolean>): InputSignal<boolean | undefined>', gave the following error.
    Argument of type 'true' is not assignable to parameter of type 'undefined'. [plugin angular-compiler]

What is the new behavior?

Add specialized overloads for input(...) with transform write type equal to read type, and add signature tests for booleanAttribute/numberAttribute with both defined and undefined initial values.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@pullapprove pullapprove Bot requested a review from kirjs April 2, 2026 10:20
@angular-robot angular-robot Bot added the area: core Issues related to the framework runtime label Apr 2, 2026
@ngbot ngbot Bot added this to the Backlog milestone Apr 2, 2026
@JeanMeche

Copy link
Copy Markdown
Member

That would be a fix for #53969, right ?

@cexbrayat

Copy link
Copy Markdown
Member Author

@JeanMeche Indeed, it looks like it is! 👍

According to the discussion between @JoostK and @devversion , maybe my fix is too naive?

But maybe it is a usable workaround until TS natively support it (even if the linked PR upstream has been closed, so it might not be soon).

@JoostK

JoostK commented Apr 3, 2026

Copy link
Copy Markdown
Member

This is interesting, I hadn't considered this. Would this behave the same as specifying TransformT = T?

@cexbrayat

cexbrayat commented Apr 8, 2026

Copy link
Copy Markdown
Member Author

@JoostK That was my first intuition, but this breaks the following test:

  __requiredWithTransformButNoWriteT = input.required<string>({
    // @ts-expect-error
    transform: (v: string | boolean) => '',
  });

I think adding overloads is the way to go.

@cexbrayat cexbrayat force-pushed the fix/input-transform-explicit-generic branch from 108df9e to 8571ed4 Compare April 8, 2026 11:04
@JeanMeche

Copy link
Copy Markdown
Member

Passing TGP

@cexbrayat

Copy link
Copy Markdown
Member Author

Is there anything I need to do to cleanup this PR?

Comment thread packages/core/src/authoring/input/input.ts Outdated
@JeanMeche JeanMeche modified the milestones: Backlog, v22 candidates Apr 29, 2026
Using explicit single generic arguments with transforms (for example, input<boolean>(false, {transform: booleanAttribute})) previously failed overload resolution.

Before this fix, type-checking produced:
````
✘ [ERROR] TS2769: No overload matches this call.
  Overload 1 of 5, '(initialValue: boolean, opts?: InputOptionsWithoutTransform<boolean> | undefined): InputSignal<boolean>', gave the following error.
    Type '(value: unknown) => boolean' is not assignable to type 'undefined'.
  Overload 2 of 5, '(initialValue: undefined, opts: InputOptionsWithoutTransform<boolean>): InputSignal<boolean | undefined>', gave the following error.
    Argument of type 'true' is not assignable to parameter of type 'undefined'. [plugin angular-compiler]
```

This change adds specialized overloads for explicit read generics.
@cexbrayat cexbrayat force-pushed the fix/input-transform-explicit-generic branch from 8571ed4 to 3ead51e Compare April 29, 2026 20:48
@pullapprove pullapprove Bot requested a review from devversion April 30, 2026 10:41

@JeanMeche JeanMeche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review-for: public-api

@JeanMeche JeanMeche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed-for: public-api

@JeanMeche JeanMeche added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release target: major This PR is targeted for the next major release and removed target: major This PR is targeted for the next major release labels Apr 30, 2026
@alxhub alxhub merged commit 1ab654c into angular:main May 1, 2026
24 checks passed
@alxhub

alxhub commented May 1, 2026

Copy link
Copy Markdown
Member

This PR was merged into the repository. The changes were merged into the following branches:

@angular-automatic-lock-bot

Copy link
Copy Markdown

This pull request has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jun 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants