#Extend Object Type When Walking Through The Parameters Of A Function
25 messages · Page 1 of 1 (latest)
I think you would have to reorganise your a function to automatically curry each method and call it as such
a("", c => {})(c => { /* context can have a different type here */ })(...)
If you have a lot of methods and this is on a hot path you might run in to performance issues with that though
@bleak pine that'd be no option for me
if there's no "ideal" solution, i'd be happy with a workaround too
Pretty sure you'll have to settle for context simply being a Record<string, uknonw> then
anything - except the structure of the accepted parameters in the a function - could be changed
or specify all your keys beforehand and make it partial
then i'd lose all the typesafety
not all
well
I bet you could make some inscrutible type that uses the length of the methods argument to add keys to the context type, but I don't think the result would even be ergonomic
do you have any other idea on your mind how i could pass data typesafely through those methods?
that's the goal behind all this code
Create each Context type separately and cast them in each function
also not typesafe
but I don't think you can be in this situation
that's messed up :/
You can still be typesafe with Record<string, unknown> and runtime checks
hey @bleak pine, me again
do you know if it would be possible to solve this if each of the functions would return the object which should be combined with the Context?
As far as I know, not without adjusting your a signature to take a set number of args
I just don't think its possible/worth spending time figuring out. TS wasn't made to track fine grained changes to object properties like this