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
typeModuleWithState<TState>={state: TState;}typeState={a: number;}typeMoreState={z: string;}functioncreateModule<TState,TActions>(state: TState,actions: TActions): ModuleWithState<TState>&TActions{return{
state,
...actions}}functionconvert<TState,TActions>(m: ModuleWithState<TState>&TActions): ModuleWithState<TState&MoreState>&TActions{return{
...m,state: {
...m.state,z: "boo"},}}constbreaks=convert(createModule({a: 12},{foo(){returntrue}}));breaks.a;// Property 'a' does not exist on type 'never'.breaks.z;// Property 'z' does not exist on type 'never'.breaks.foo()// Property 'foo' does not exist on type 'never'.constmod=createModule({a: 12},{foo(){returntrue}})constworks=convert(mod);works.a;// numberworks.z// stringworks.foo();
π Actual behavior
The first scenario (breaks) fails the infer the correct type of the passed argument. Second scenario works works as expected. The only difference between the two is that in the latter the argument is first assigned to a variable.
π Expected behavior
Both scenarios work exactly the same.
The text was updated successfully, but these errors were encountered:
You probably meant to write breaks.state.a, breaks.state.z, works.state.a, works.state.z instead (because that is what is expected to work according to the runtime code and types if I'm not reading it incorrectly). Also your playground link is inconsistent with the code.
This seems to be related to #40439. Because if you make foo a non-function say true then it starts working. TypeScript seems to topple with inference when there's a functional property in complex cases.
Bug Report
π Search Terms
Contextual inference
Does not exist on type 'never'
π Version & Regression Information
Tested in 4+, and this is the behavior in every version I tried.
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
The first scenario (
breaks
) fails the infer the correct type of the passed argument. Second scenarioworks
works as expected. The only difference between the two is that in the latter the argument is first assigned to a variable.π Expected behavior
Both scenarios work exactly the same.
The text was updated successfully, but these errors were encountered: