TypeScript Version: 2.9.2
Search Terms: generic function pipe contextual type wrong overload
Code
These examples are stripped down versions of Node's parse function in the querystring module and Lodash's values and fromPairs functions.
These are issues we ran into when trying to use these functions with a pipe function.
declarefunctionpipe<A,B,C>(ab: (a: A)=>B,bc: (b: B)=>C): (a: A)=>C;{typeParsedUrlQuery={[index: string]: string};declarefunctionparsedUrlQueryString(str: string): ParsedUrlQuery;declarefunctionparsedUrlQueryString<Textends{}>(str: string): T;declareconststringToString: (s: string)=>string;// $ExpectType (a: string) => ParsedUrlQuery// but got (a: string) => {}// Note: if we comment out the last overload for `parsedUrlQueryString`, we get the expected// type.constfn=pipe(stringToString,parsedUrlQueryString,);}{declarefunctionvalues<T>(object: {[index: string]: T}|null|undefined): T[];declarefunctionvalues<Textendsobject>(object: T|null|undefined): Array<T[keyofT]>;declarefunctionvalues(object: any): any[];declareconststringDictToStringDict: (sd: {[index: string]: string},)=>{[index: string]: string};// $ExpectType (a: { [index: string]: string; }) => string[]// but got (a: { [index: string]: string; }) => any[]// Note: if we comment out the last two overloads for `values`, we get the expected type.constfn=pipe(stringDictToStringDict,values,);}{declarefunctionfromPairs<T>(pairs: [string,T][]|null|undefined): {[index: string]: T};declarefunctionfromPairs(pairs: any[][]|null|undefined): {[index: string]: any};// $ExpectType (a: {}) => { [index: string]: number; }// but got (a: {}) => { [index: string]: any; }// Note: if we comment out the last overload for `fromPairs`, we get the expected type.constfn=pipe(({}: {}): [string,number][]=>[['foo',1]],fromPairs,);}
TypeScript Version: 2.9.2
Search Terms: generic function pipe contextual type wrong overload
Code
These examples are stripped down versions of Node's
parsefunction in thequerystringmodule and Lodash'svaluesandfromPairsfunctions.These are issues we ran into when trying to use these functions with a
pipefunction.