You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot infer const array when put as function args since version 4.2Β #44631
typeState={foo: string}// Selector is a function which has zero or some args.typeInputSelector<T,P=void>=(state: State,props: P,
...args: any[])=>T;exportfunctioncreateInputSelector<T,P=void>(selector: InputSelector<T,P>): InputSelector<T,P>{returnselector;}// In this sample, return tuple array as is. exportfunctioncreateSelectors<T,RextendsreadonlyInputSelector<T,any>[],>(selectors: R): R{returnselectors}// Case 1: Use defined const array// -> All version: readonly [InputSelector<string, void>]constconstArr=[createInputSelector((state: State)=>state.foo)]asconstconstres1=createSelectors(constArr)// Case 2: Define const array in function args// -> v4.2.2~: readonly [InputSelector<string, any>]// ~v4.1.5: readonly [InputSelector<string, void>]constres2=createSelectors([createInputSelector((state: State)=>state.foo)]asconst)
π Actual behavior
Cannot infer tuple type since v4.2 (return type becomes extension source)
π Expected behavior
Infer tuple type even when define const array in function args
This is the intended behavior as of 4.2; a generic default is only applied in the presence of zero inference candidates, but createSelectors applies a contextual inference site from its constraint, thus supplying a candidate for P.
Activity
RyanCavanaugh commentedon Jun 17, 2021
This is the intended behavior as of 4.2; a generic default is only applied in the presence of zero inference candidates, but
createSelectorsapplies a contextual inference site from its constraint, thus supplying a candidate forP.dora1998 commentedon Jun 18, 2021
Thank you for the quick reply.
I undestand inference context, but why did this behavior change in 4.2?
I cannot find the relevant PRs or issues, so if you can, could you tell me those?
typescript-bot commentedon Jun 20, 2021
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.