I'm currently working on a helper function that associates a Symbol with a value.
function setCustomSymbol<S extends symbol, T>(symbol: S, data: T, defaultValue: any = true): S & T { /*...*/ }
The issue I'm facing is trying to instruct TypeScript that the output of this function should be a value with the specified symbol property. This way, I can use it like this:
const MySymbol = Symbol();
const obj = {};
const resultWithCustomSymbol = setCustomSymbol(MySymbol, obj);
resultWithCustomSymbol[MySymbol] = true;
Is there a way to achieve this? I experimented with unique symbol
but couldn't quite make it work. Thank you for your assistance!