I am Software Developer, currently interested in static type languages (TypeScript, Elm, ReScript) mostly in the frontend land, but working actively in Python also. I am available for mentoring.
Hi David thank you for the answer.
But your code doesn't make errors when it should, so there are no compile time guarantees. I put in the snippet two places where the error should occur, you see there 🛑 icon. Even more the code you have provided compiles for any second argument like concatToField(test, 'anything', 'test');.
constconcatToField=<TextendsRecord<string,any>,KextendskeyofT&(T[K]extendsstring?string:never)>(obj:T,key:K,payload:string):T=>{constprop=obj[key];// compile error should not be herereturn{...obj,[key]:prop.concat(payload)};// compile error should not be here}
Hi David thank you for the answer.
But your code doesn't make errors when it should, so there are no compile time guarantees. I put in the snippet two places where the error should occur, you see there 🛑 icon. Even more the code you have provided compiles for any second argument like
concatToField(test, 'anything', 'test');
.So try again! And good luck.
Ah, was just missing some brackets. :/
Playground