Default type T for InputFunction's TransformT#59649
Default type T for InputFunction's TransformT#59649angelaki wants to merge 3 commits intoangular:mainfrom
T for InputFunction's TransformT#59649Conversation
|
Why don't you just let the inference do it job ?
|
Oh wow, I actually wasn't aware of this! Thank you! But where is this magic? How does the signal know that it's value is not of the type of the first argument only? Never the less, would a default value hurt? |
|
When the generic isn't specified, typescript will try to infer it. I wouldn't expect |
I know about this infering but the values type is But: right now, specifying only one type Edit: by the way, here the reason I created this PR: https://stackoverflow.com/questions/79082672/unable-to-add-types-to-input-with-transform-functionality |
This isn't the case; TypeScript requires that if some type arguments are present, then all non-optional type parameters must also have a corresponding type argument. A default type as introduced in this PR makes it valid, but only for atypical usages of Concretely, in your example you mention to have multiple= input<boolean | 'append', boolean | 'append'>(true, { transform: v => v === 'append' ? 'append' : coerceBooleanProperty(v) });this is unlikely what you intent to represent; e.g. the This change also hinders potential advances in TypeScript that would be true solutions for this case, namely microsoft/TypeScript#54047 and microsoft/TypeScript#26349. It's unclear if such change will ever make it into TypeScript, but introducing a default value in Angular now will make such future feature inapplicable. Hence we do not want to go forward with this change. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Description
Curious why this isn't the default behavior so I'm quite sure there is a reason? Never the less, find it much more comfortable to not be forced to always write the type twice on using a converter:
multiple= input<boolean | 'append', boolean | 'append'>(true, { transform: v => v === 'append' ? 'append' : coerceBooleanProperty(v) });-->
multiple = input<boolean | 'append'>(true, { transform: v => v === 'append' ? 'append' : coerceBooleanProperty(v) });Does this PR introduce a breaking change?