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
Unexpected error/bad inference for generic composed function inside pipe #25791
Search Terms: index signature pipe generic lost dictionary
Code
declarefunctionpipe<V0,T1,T2,T3>(fn0: (x: V0)=>T1,fn1: (x: T1)=>T2,fn2: (x: T2)=>T3,): (x: V0)=>T3;declarefunctiongetStringDict(): {[index: string]: string};declarefunctionstringDictIdentity<T>(stringDict: {[index: string]: T;}): {[index: string]: T};/*Without strict enabled:Expected type (x: {}) => { [index: string]: string; }Actual type (x: {}) => { [index: string]: {}; }With strict enabled, unexpected type error:Argument of type '<T>(stringDict: { [index: string]: T; }) => { [index: string]: T; }' is not assignable to parameter of type '(x: {}) => { [index: string]: {}; }'. Types of parameters 'stringDict' and 'x' are incompatible. Type '{}' is not assignable to type '{ [index: string]: {}; }'. Index signature is missing in type '{}'. */constfn=pipe(getStringDict,x=>x,stringDictIdentity,);//// Workarounds//declarefunctionidentity<T>(a: T): T;constfn2=pipe(getStringDict,identity,stringDictIdentity,);constfn3=pipe(getStringDict,x=>x,x=>stringDictIdentity(x),);
Revisiting this. I believe the issue can be narrowed down to:
{declareconstpipe: {<A,B,C,D>(ab: (a: A)=>B,bc: (b: B)=>C,cd: (c: C)=>D): (a: A)=>D;};declareconstgetArray: ()=>string[];declareconstfirst: <T>(ts: T[])=>T;/* Without `strictFunctionTypes` enabled: Expected type: `(a: {}) => string` Actual type: `(a: {}) => {}` */constfn=pipe(getArray,x=>x,/* With `strictFunctionTypes` enabled, unexpected type error: Argument of type '<T>(ts: T[]) => T' is not assignable to parameter of type '(c: {}) => {}'. Types of parameters 'ts' and 'c' are incompatible. Type '{}' is missing the following properties from type '{}[]': length, pop, push, concat, and 25 more. */first,);// Workaround 1: use `identity` functiondeclareconstidentity: <T>(value: T)=>T;constfn2=pipe(getArray,identity,first,);// Workaround 2: wrap last functionconstfn3=pipe(getArray,x=>x,x=>first(x),);}
changed the title [-]Unexpected error/bad inference for generic inside of index signature[/-][+]Unexpected error/bad inference for generic composed function inside `pipe`[/+]on Feb 14, 2019
Activity
OliverJAsh commentedon Feb 13, 2019
Revisiting this. I believe the issue can be narrowed down to:
Any ideas Mohamed Hegazy (@mhegazy) Wesley Wigham (@weswigham)? Does this help?
[-]Unexpected error/bad inference for generic inside of index signature[/-][+]Unexpected error/bad inference for generic composed function inside `pipe`[/+]