I would like to have some feature that infers any possible types from the given object in the generic function.
For instance I have a function that receives Object, and I want to have a more specific callback than 'any'.
Current code:
functiona(obj: Object,f: (value: any)=>any){for(varpinobj)if(obj.hasOwnProperty(p)){(<any>obj)[p]=f((<any>obj)[p])}}a({x:1},(value: any)=>(<number>value)+1);I wish I had something with more strict typing.
functiona<TextendsObject,Value: union_of_properties_types_of(T)>(obj: T,f: (value: Value)=>Value){for(varpinobj)if(obj.hasOwnProperty(p)){(<any>obj)[p]=f(<Value>(<any>obj)[p])}}// 'f' is denoted to number => numbera({x:1},value=>value+1);// 'f' is string => stringa({x:"x",y:"y"},value=>{returnvalue+"z";});
I would like to have some feature that infers any possible types from the given object in the generic function.
For instance I have a function that receives Object, and I want to have a more specific callback than 'any'.
Current code:
I wish I had something with more strict typing.