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
I have a typescript issue unrelated to these challenges but I was hoping it's okay to ask for help on here.
I want to create a new function from an initial function, with the initial function taking a single object argument and the new function taking the same single object argument apart from populated fields. I've got something like this so far:
function returnNewFunc<TArg extends { b?: string }>(
initialFunc: (arg: TArg) => void
) {
const newFunc = (arg: Omit<TArg, "b">) =>
initialFunc({ ...arg, b: "hello" });
return newFunc
}
const funcA = ({ b, c }: { b: string; c: string }) => {
console.log(b, c);
};
const funcB = returnNewFunc(a)
b({c}) // funcB should have 'c' as the only field in its argument
The issue here is I get a "could be instantiated with a different subtype of constraint" typescript error within newFunc, so I must be doing something wrong.
I've also created a stack overflow post of the same issue.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a typescript issue unrelated to these challenges but I was hoping it's okay to ask for help on here.
I want to create a new function from an initial function, with the initial function taking a single object argument and the new function taking the same single object argument apart from populated fields. I've got something like this so far:
The issue here is I get a "could be instantiated with a different subtype of constraint" typescript error within
newFunc
, so I must be doing something wrong.I've also created a stack overflow post of the same issue.
Beta Was this translation helpful? Give feedback.
All reactions